A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Not Sure how to describe my problem (has to do with rotation)

  1. #1
    FK's Resident ...... Resident flashMasterHand's Avatar
    Join Date
    Aug 2003
    Location
    Connecticut, USA
    Posts
    168

    Not Sure how to describe my problem (has to do with rotation)

    Hey All,

    I am working on a game (will try this in the games forum if I don't get any replies) that is a tactical simulation (if that is even a genre ) You move your units (top down view) with the mouse. When they get within a certain range of an enemy, they will start fighting each other. The problem I am having is that when the units see each other, I need them to turn and face each other. It would be great if I could get them to turn until they were looking a each other (ie over a few frames), but just having them instantly turn to face each other is fine (ie the moment they see each other, they take one frame to turn. I just am not sure how to go about doing this. Any help is appreciated!

    Thanks,
    Dave
    DaveWasmer.com
    Programmers don't die, they just GOSUB without RETURN.

  2. #2
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    Well, you should have a variable telling you the rotation of the units at any given time. I'm assuming you have the movement random, and therefore rotation is also random. So, if one unit sees another unit.
    unit1._rotation = unit2._rotation + 180 (or 2pi depending what the units are)

    If you can visualize this, adding 180 degrees will make the one unit face the other. Hope this helps a little

  3. #3
    FK's Resident ...... Resident flashMasterHand's Avatar
    Join Date
    Aug 2003
    Location
    Connecticut, USA
    Posts
    168
    What if they aren't facing the oppisite directions??

    I thought it would be basically taking the same forumla for the cars that can drive in any direction in a top down view:

    Math.sin(_rotation*(Math.PI/180))*speed

    and somehow reversing it. So you would get the slope of the line that passes through the enemy's point and the marine's point. Then, using that reversed formula, work backwards from the slope to the angle. I know that makes no sense at all, I can't explain this stuff in text. Anyway, the movements aren't random.
    Programmers don't die, they just GOSUB without RETURN.

  4. #4
    FK's Resident ...... Resident flashMasterHand's Avatar
    Join Date
    Aug 2003
    Location
    Connecticut, USA
    Posts
    168
    Nevermind, I figured it out. Thanks for your help.
    Programmers don't die, they just GOSUB without RETURN.

  5. #5
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    My code would have worked though. Example, unit 1 is facing to the right (0 degrees). Unit 2 is somewhere to the right of unit 1 facing say...45 degrees. When unit 2 "sees" unit 1 it will according to my code rotate to unit 1 +180 degrees, which will make it rotate to 180 degrees, or facing to the left (towards unit 1). This would work for any directions.....

    Regardless, glad you got it figured out.

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