# Help!! I Cant make the missile turn acording to the Speed!

• ### 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

• 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 Thursday, April 26, 2012 7:03 PM
Thursday, April 26, 2012 5:44 PM

### All replies

maybe this program is not so good.   but  works.

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

Thursday, April 26, 2012 1:19 PM
• 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 Thursday, April 26, 2012 7:03 PM
Thursday, April 26, 2012 5:44 PM
• Thank you very much!

it worked very well.  thanks for the code!

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

Bugs are fixed.  This works smoothly.

Friday, April 27, 2012 3:57 PM