none
Help!! I Cant make the missile turn acording to the Speed! RRS feed

  • Question

  • DXG967

    in This program I am trying to make something having to do with artillery wars but, as the missile comes out of the barrel I cant make it always make it point the direction that is going (eg; pointing down when its falling and pointing flat when its flying strait) could anyone reply with a sorce code that would show me how to do that?


    Thursday, April 26, 2012 2:41 AM
    Answerer

Answers

  • We need to calculate the velocity vector and convert this to an angle to rotate the arrow.  The rotation is in degrees clockwise with 0 in the X direction.  This should do the trick.  First get the velocities, then get the angle, then rotate.

    Nice game in progress.

      'Rotate the arrow with direction
      velX = Vh2
      velY = Vv2 + Timenow2 * Gravity
      If (velX = 0) Then
        angleArrow = Math.Pi/2
      Else
        angleArrow = Math.ArcTan(velY/velX)
      EndIf
      If (velX < 0) Then
        angleArrow = angleArrow+Math.Pi
      EndIf
      Shapes.Rotate(Ball2,angleArrow*180/Math.Pi)
    

    • Marked as answer by Zock77Editor Thursday, April 26, 2012 7:03 PM
    Thursday, April 26, 2012 5:44 PM
    Moderator

All replies

  • How about this.   JWZ964-0       

    maybe this program is not so good.   but  works.

    ( If textwindow use, graphics.keydown doesnot work. So I used shape message.)


    * Comments are added.  JWZ964-0
    Thursday, April 26, 2012 1:19 PM
    Answerer
  • We need to calculate the velocity vector and convert this to an angle to rotate the arrow.  The rotation is in degrees clockwise with 0 in the X direction.  This should do the trick.  First get the velocities, then get the angle, then rotate.

    Nice game in progress.

      'Rotate the arrow with direction
      velX = Vh2
      velY = Vv2 + Timenow2 * Gravity
      If (velX = 0) Then
        angleArrow = Math.Pi/2
      Else
        angleArrow = Math.ArcTan(velY/velX)
      EndIf
      If (velX < 0) Then
        angleArrow = angleArrow+Math.Pi
      EndIf
      Shapes.Rotate(Ball2,angleArrow*180/Math.Pi)
    

    • Marked as answer by Zock77Editor Thursday, April 26, 2012 7:03 PM
    Thursday, April 26, 2012 5:44 PM
    Moderator
  • Thank you very much!

    it worked very well.  thanks for the code!

    Thursday, April 26, 2012 7:05 PM
    Answerer
  • JWZ964-1    

    Bugs are fixed.  This works smoothly.

    Friday, April 27, 2012 3:57 PM
    Answerer