A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: car hit??

  1. #1
    incredibulus-actionscriptum magnetos's Avatar
    Join Date
    May 2001
    Posts
    2,160

    car hit??

    ok guys look at this image



    the question is how do i make the red mc which is inside the car(rectangles) mc rotate in a way that its always hitting the walls?
    this way (i think) the car hitTest should be more accurate and it will require only one inner mc assuming you dont reverse

    any idea codewise???

    thanks

  2. #2
    Junior Senior
    Join Date
    Nov 2000
    Location
    sydney
    Posts
    565
    If you're trying to do what i *think* you're trying to do... I do that with 4 red mc's inside the rectangle and no code at all
    If the car is moving forward (not sliding) you probably only need to check 2 of the 4.

  3. #3
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    did you want this to work only within the square shape or can the walls be any angle??
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  4. #4
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    http://www.flashkit.com/board/attach...postid=2356227

    http://www.flashkit.com/board/showth...hreadid=446301

    Hittest against all four points using a loop or compare the _x,_y coords against your tilebased engine - then adjust velocity accordingly. I used something simialir in my old GTA engine...

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  5. #5
    incredibulus-actionscriptum magnetos's Avatar
    Join Date
    May 2001
    Posts
    2,160
    Originally posted by BlinkOk
    did you want this to work only within the square shape or can the walls be any angle??
    yes blink if the red hit detection mc moves within the car according to its rotation i believe that no matter how the background is it should work for straight and angled walls "i think"
    maybe i might have to add another mc in the back but for now i wannna try with one i just cant seem to translate to code

    the idea of having 4 mc inside the car its ok but i am trying to optimize the all thing by having only one hit check

    perhaps i am way off am i ?


    thanks guys

  6. #6
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    as long as the car is going forward! although you could just reverse the test if it's going backward.
    give me a little while to think about it. i reckon you're right!
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  7. #7
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    i think you could prolly reduce it to one test but i'm still workin on the math. however mabey the math for that would make it not worthwhile so anyway here's the two point check.
    1. you need to take into account the direction of travel. if your going forward the the leading two corners are going to hit.
    2. if your going backward then the trailing to corners are going to hit.
    3. you can check for a hit by x = car._width / 2 and y = car._height / 2. assuming the cars initial position is facing upwards then the leading right will be p = { x: x, y: y * -1) and the leading left will be p = { x: x * -1, y: y * -1 }. if you use car.localToGlobal(p) and walls.globalToLocal(p) then you can check if Math.abs(p.x) > walls._width / 2 or Math.abs(p.y) > walls._height / 2 to determine if the car has collided with the walls. p will also be the point of collision. If your going backward then the y * -1 becomes just y.
    No hittests!! have a think about it and i'll see if i can make a .fla.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  8. #8
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    this is the code. i added a proximity test up front so if the car was nowhere near the wall it wouldn't go into the point testing.
    http://www.nlc.net.au/~oceana/games/carWalls.swf
    http://www.nlc.net.au/~oceana/games/carWalls.zip
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  9. #9
    incredibulus-actionscriptum magnetos's Avatar
    Join Date
    May 2001
    Posts
    2,160
    Originally posted by BlinkOk
    this is the code. i added a proximity test up front so if the car was nowhere near the wall it wouldn't go into the point testing.
    http://www.nlc.net.au/~oceana/games/carWalls.swf
    http://www.nlc.net.au/~oceana/games/carWalls.zip
    thats veeeery cool blink i havent looked at the code yet thuogh
    the way i was trying to do it was with the red dot inside the car
    which in a actual game you make it invisible
    but your way looks cool
    anyway i gonna take a look at the code now......


    thanks blink you'r da man

  10. #10
    Senior Member random10122's Avatar
    Join Date
    Mar 2002
    Location
    Sheffield, UK
    Posts
    1,747
    Why ignore my answer? It may be tricky trigonometry but it works.

    fracture2 - the sequel
    fracture - retro shooter
    blog - games, design and the rest

    "2D is a format, not a limitation" -Luis Barriga

  11. #11
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    i not 100% sure but i think the 4 point hit test is a little slow and most importantly he needs the point of impact. if i know magnetos he's workin on some car collision physics.
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  12. #12
    incredibulus-actionscriptum magnetos's Avatar
    Join Date
    May 2001
    Posts
    2,160
    blink is right !!
    sorry random if it seemd like i ignored your answer but i didnt infact i did dowload the fla and took a look at it

    thanks random

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