A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: rotation delay

  1. #1
    Junior Member
    Join Date
    Dec 2000
    Posts
    2

    Question

    I am creating a simple movie based on the 'movement-joystick' sample in flash MX. I am moving a tank around the screen using an on screen joystick and I want the gun turret on the tank to rotate slower than the tank but eventually catch up if the position is maintained (if that makes sense!!). I am currently setting the rotation of the tank to the rotation of the on screen joystick movieclip.


    Also when I fire the cannon on the tank I want to calculate the angle of the gun turret and recoil the whole tank based on the turret angle. The recoil would need the _x and _y of the tank to be affected but based on the turret angle.

    Any help would be greatly appreciated.

    Keene

  2. #2
    If you like to rotate the canon slower as the body, devide the amount of rotation you add to the canons rotation through a value greater than one. This should slow down rotation, but let it end at the same point. Just some time after the body of your tank.

    For your angle calculation take a look at the following thread:
    http://board.flashkit.com/board/show...hreadid=279907
    This should give you an idea on how to solve your problem.


  3. #3
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    you have a target rotation - where you want it to rotate to, and an existing rotation - your _rotation property.

    subtract existing from target and divide by some factor, between 2 and 10 tends to work good. add that to the existing.

    diff=target-_rotation;
    _rotation+=diff/2;

    this just leaves one problem.
    say your target it 340 (about 2:00 on a clock dial)
    existing is 20 (about 4:00)
    your cannon will spin all the way around clockwise to get to the target, rather than just 40 degrees counter clockwise.

    so add these lines before moving:

    if(diff<-180) diff+=360;
    if(diff>180) diff-=360;

  4. #4
    Junior Member
    Join Date
    Dec 2000
    Posts
    2
    Thanks guys, that's working great now. The problem was that I had the turret movieclip as part of the body movie clip which was affecting the maths.

    Thanks again.

    Keene

    http://www.markkeene.co.uk

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