A Flash Developer Resource Site

Page 5 of 21 FirstFirst 12345678915 ... LastLast
Results 81 to 100 of 407

Thread: MarioKart style flash engine

  1. #81
    Participant jide's Avatar
    Join Date
    May 2003
    Posts
    264
    how did u do the 3D for the lil guy? did you render it in FLASH??!?! If not, then how did you get the proper scaling and stuff (like how did you make him smaller and **** when he gets further and position in the 3D plane.
    glhf

  2. #82
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    i modelled him using swift3d and then animated a 360 degree spin (120 frames, which explains the bandwidth) i used the flash samuri calculation to convert 3d points to 2d.
    for the trees AND the dude i did was this ;
    //
    // Note
    I good deal of this deals with the mini-map you see at the top right-hand corner of the stage. it is important to remember that even though it is scaled down, the co-ordinates used will be as though it were scaled to 100%.
    //
    // Position and scaling
    //
    i took the (x,y) pos for the object from the map[See rotation] (which in 3d is the x,z). now coz the ground is flat, and everything sits on the ground, the 3d y position will always be the same (note that the center of all the object mc's is at the bottom).
    i just guestimated where the camera would be which determines the y position. the higher the camera lower y value. i think i set my y value to -80.
    now i have an x,y,z value for where the object meets the ground. i can use the flash samauri method to convert that x,y,z value to a 2d x,y value.
    i then gave each object a height (have a look in the elvis and tree mc and you'll see a height=value statement). i subtracted the height value from the 3d y position which gives a 3d y point for the top of the object (the x and z values are the same). using flash samauri i converted that to a 2d point.
    now i can calculate the height of the object (on the stage) by subtracting the top 2d y pos from the bottom 2d y pos. i then set the _height of the object to that value and set _xscale to equal _yscale which matintains the aspect ratio of the object (flash will automatically calculate the _yscale of an object when you set the _height).
    Finally, because the scene seems to be flattened out i had to scale the resulting x,y co-ordinates to fit the screen. i'm not sure why i need to do this but i multiplied the y value by 10 and the x value by 1 (i know i don't need to do the x calculation but i figured i may have to multiply it by something other than one in the future). this gives me a 10:1 aspect ratio.
    //
    // Rotation
    //
    Now the flash samauri method will only work when the camera is at right angles to the scene. this presents a problem when the car turns and thus puts the scene at another angle to the camera.
    to solve this problem i convert the x,y co-ordinates from the map to the camera (car in the map).
    the map is a mini-map (scaled down to 10%), notice how the car moves around the map and is rotated according to the keyboard.
    so to convert a point on the map to a co-ordinate that is at right angles to the camera i use map.localToGlobal(point) to convert the map point to stage co-ordinates and then use map.car.globalToLocal(point) to convert the stage point to the car's co-ordinates and wala i now have an (x,y) pos that is at right angles to the camera.
    you could do exactly the same thing by using the car as the center and applying some trig to the point but i think the localtoglobal is easier and quicker.
    //
    // Angle to camera (of Elvis)
    //
    I'm still not sure i got the angle to camera right but the basic principle is this. using the opponent mc within the map i take a point that is directly behind and a point that is directly in front of the opponent.
    i then convert these points to the (car/camera) using the method described above.
    i then calculate the angle between these two points and scale it to the number of frames in my elvis mc (120). So the angle range will be 0-360 and the frame range will be (1-120). the calculation is roughly;
    frame = int(angle * 120 / 360). a bit of extra code makes a zero result 1.
    hope this helps
    blink
    Flash samurai 3d to 2d calculation;
    http://www.macromedia.com/devnet/mx/...murai_ch2.html
    which is basically this;
    Code:
    D = 400;
    // calculate the perspective ratio 
    // the D value is actually the view planes distance from the camera
    // have a look at the "3D for dummies" tutorial (here at fk) for an explanation of the view plane
    perspective_ratio = D / (D + z); 
    // calculate position of point on computer screen 
    perspective_x = x * perspective_ratio; 
    perspective_y = y * perspective_ratio; 
    (Don't try and understand why it works just know that it works
    Last edited by BlinkOk; 06-26-2003 at 07:20 PM.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  3. #83
    for the win Asclepeos's Avatar
    Join Date
    Dec 2000
    Posts
    388
    funny how the samurai guy was a senior in high school when he wrote that. But I recall the proof for 3d to 2d was in some Friend of ED book. oh well.

  4. #84
    Member
    Join Date
    May 2003
    Posts
    69
    This is getting so cool!! I was trying to look for the maze engine on this site that strille did, or the raycasting engine, but I can't seem to find it, can someone point to it for me. thanks. Almost like MarioKarts!!!

  5. #85
    avatar free
    Join Date
    Jul 2002
    Location
    UK
    Posts
    835
    Strille's raycasting v1: http://www.flashkit.com/movies/3D/En...6852/index.php

    Strille's raycasting v2: http://www.flashkit.com/movies/3D/En...8022/index.php

    Or his cool website (see his links)
    jonmack
    flash racer blog - advanced arcade racer development blog

  6. #86
    Participant jide's Avatar
    Join Date
    May 2003
    Posts
    264
    Whoa!! You totally overkilled that question, but thanks! Im sure it'll help others who will want to learn.

    I just wasnt sure of the method you were using.

    Personally, I spent a lot of time trying to figure out the 3D to 2D thing on my own. I came up with 2 formulas (one for findig a point's X value, one for the Y value). Now this need only apply to vector 3D mind you... wait a minute, you could actually use this technique for images that you want to 3D afy (by simply interpretting 2 opposite corners of the image as points and messing with the heigh and width accordingly).

    I'm sure your technique works better, but here's my formulas (they are for points):

    _x = (atan(x/z)+endAngleofRangeofView)/degreesofViewSpan
    _y = (atan(y/z)+endAngleofRangeofView)/degreesofViewSpan

    seems pretty simple, but it took me about 2 months (not very focused, but still) for me to figure these out.

    Unfortunately, this is only theory I have worked out on paper, so it may not actually work

    I still gotta check out that Samuri thing. Please tell me if there are any flaws in my theory (the theory is based on the human eye, the cone like range of view it has, and I EUREKA!ed when I plotted that out (a plane at a time) for someone looking down a hallway)
    glhf

  7. #87
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    jide: i'll have a go at using you algorythm in the game. it looks interesting.
    this is a just-for-fun post. i added a player dude "pete the pirate" (that thing sticking outta his face is a knife). i also change the individual tree to clumps of trees, i think it kinna makes it look a bit more crowded. the fps took a little bit of a hit but i expected that.
    its a massive 470k now and i would expect it to be 700-800k when finished unless i can figure out some more graphics optimization.
    http://www.nlc.net.au/~oceana/games/loader.html (with preloader)
    anyways have fun!
    blink
    ps: the code is a mess right now so i won't bother posting it. gimme a day or so and i'll clean it up and add the other dude (sarg) and then i'll post it.
    Last edited by BlinkOk; 06-27-2003 at 12:16 AM.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  8. #88
    .fla vont's Avatar
    Join Date
    Oct 2001
    Posts
    473
    wow .. that was real cool .. great work.

  9. #89
    Senior Member
    Join Date
    Aug 2001
    Posts
    101
    nice pirate

    u need to move the 'thepic' movieclip (the one with the instance name 'pic' from my code) up about 8 pixels from the center point of pic (the movieclip that gets attached), this will mean that the road will rotate from under the pirate, rather than from behind him

    if u have a look at my original link u'll see what I mean

    also have u changed the way the trees move? they seem to jump when I let go of left or right. dirty!

  10. #90
    Senior Member lapo73's Avatar
    Join Date
    Jun 2003
    Location
    italy
    Posts
    395
    hi,
    your sample is really good and very interesting !

    Would you like to publish it here ? >> www.gotoandplay.it

    we are gathering developers and passionates to exchange their ideas and game prototypes etc ...

    your work is really educational !

    Drop me a line if you're interested.

    bye

    Lapo
    webmaster@gotoandplay.it
    www.gotoandplay.it
    Flash game developers community
    www.smartfoxserver.com
    Multiplayer Flash Server

  11. #91
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    wow guys that is absolutly AWESOME i wish... well i could wish all day but thats awesome

    blink: he he - im a cockroach in toad land boy did i have fun on both thursdays at skool he he - neway stuff skool!!! IM ON HOLIDAYS

  12. #92
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    percy: your right about the trees percy, it's a stupid mistake i made before posting. i'll have a look at the rotation point too.
    leight: mabey us canetoads will get a little dignity back in origin 3
    lapo73: sounds interesting]
    vont: thanks
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  13. #93
    Senior Member lapo73's Avatar
    Join Date
    Jun 2003
    Location
    italy
    Posts
    395
    lapo73: sounds interesting
    ok !
    let me know if you wish to publish it on my site.

    bye

    Lapo
    webmaster@gotoandplay.it
    www.gotoandplay.it
    Flash game developers community
    www.smartfoxserver.com
    Multiplayer Flash Server

  14. #94
    leight.com.au leight's Avatar
    Join Date
    Sep 2002
    Location
    australia
    Posts
    1,437
    i found a bug guys... turn the fog on and off and that elvis guy goes up in the air for a lil bit infront of you:S

    blink: yes joey johns is a mighty fine player go the banana kick he he didnt u love it when kennedy smashed price was it??? neway ill stop spaming this amazing thread now!!! GO THE BLUES whitewash them toads

  15. #95
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    i need a little help here.
    i tried what percy said to change the pivot point and it didn't work (i'm using strille's code) so i'm prolly doin something wrong.
    i created a test .fla so you guys could have a look and see what you can do.
    i basically want to be able to move the pivot point from the bottom center of the screen to somewhere else.
    http://www.nlc.net.au/~oceana/games/pivot.html (27k)
    http://www.nlc.net.au/~oceana/games/pivot.zip
    thanks in advance for the help.
    blink
    leight: i think kennedy will do time for that, but i'm sure that won't bother him. bronco's go around tonight so mabey i'll get a little back. re the fog, i'm workin on that now.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  16. #96
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Originally posted by jide
    Personally, I spent a lot of time trying to figure out the 3D to 2D thing on my own. I came up with 2 formulas (one for findig a point's X value, one for the Y value). Now this need only apply to vector 3D mind you... wait a minute, you could actually use this technique for images that you want to 3D afy (by simply interpretting 2 opposite corners of the image as points and messing with the heigh and width accordingly).

    I'm sure your technique works better, but here's my formulas (they are for points):

    _x = (atan(x/z)+endAngleofRangeofView)/degreesofViewSpan
    _y = (atan(y/z)+endAngleofRangeofView)/degreesofViewSpan
    But what the heck are those endAngleofRangeofView and degreesofViewSpan variables? Can you make picture of this system?

  17. #97
    Senior Member
    Join Date
    Aug 2001
    Posts
    101
    i... i just lied, so have edited my post....

  18. #98
    Participant jide's Avatar
    Join Date
    May 2003
    Posts
    264
    Think about your eyes. You can't see behind you can you? The view span is how "widely" you can see. Your actual view span can be calculated quite easily. Just mark the left most and right most point you can see, and calculate the degrees between them using trig.

    Here is an example of a view range would be this (the degrees of view range for this one would be about 45 degrees):

    Code:
    \                  /
     \                /
      \              /
       \            /
        \          /
         \        /
          \      /
           \    /
            eyes
    The end of view range is simply the rightest side. I also used a projector as an analogy to help me try to understand it.

    Think about how u would go about placing the x's at the top to the
    of the diagram bottom while still being proportional, and still fitting within the view range. You kinda have to think of it in terms of arcs. If you moved along the arc, the z value would remain constant, and the angle in relation to the eye would change. I'll try to whip something up in paint later, cuz im sure this is very confusing to you because Im not that good at explaining things in english
    glhf

  19. #99
    Illuminatus! fospher.com's Avatar
    Join Date
    Jan 2002
    Location
    5th Dimension
    Posts
    2,185
    I cant keep my eyes off this thread...but dont have time to read all the posts. And its all open-source too - someday I'll rip apart that engine

  20. #100
    Neoteric Lukstr's Avatar
    Join Date
    Apr 2002
    Location
    "The Cave"
    Posts
    695
    Geeze.. It sure is beautiful. Mbenney, don't you wish we had've jumped on it and done this first? We would get all the credit Nice job Percy, you beat me to the punch on this, I was going to do it this summer when I had some (large amounts) of free time.

    Oh yeah, by the way, hills are actually not that much harder, you just need to at a height map, and then increased the height of the strips... Ok, it's sort of hard to explain... get Top Gear 2 and run it in 400% view, you'll see what I mean.
    - Lukstr

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center