Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

While rotating a tank turret, how do I properly launch a rocket from the current rotation?

Asked by 7 years ago

I've created a custom character avatar for my game which is a tank. I have the movement script working properly, however, the firing of rockets is a bit off. If the tank is rotated at 0, 90, 180 or 270 then the rocket fires in a straight line. Whenever the tank is slightly rotated off of those 90 degree increments the rocket fires with an arc in the x or z directions. What can I do to correct for this issue? My CFrame calculation is below. 'MyTurret' is the tank and 'TurrentEngine' is a hidden part at the end of the barrel of the tank with the front side pointed in the same direction as the front of the tank. The script is attached to the rocket, so script.Parent refers to the rocket part itself.

script.Parent.CFrame = MyTurret.Value.TurretEngine.CFrame * CFrame.new(MyTurret.Value.TurretEngine.CFrame.lookVector)

Any help would be greatly appreciated!

Thanks in advance.

Answer this question