P
P
PRIYD2020-05-25 15:52:37
C++ / C#
PRIYD, 2020-05-25 15:52:37

How to move an object based on an angle?

Hello, problem: a game in the style of SpaceShooter, there is a ship with constant movement (straight), but by implementing the rotation of the ship (by pressing the keys), I realized that it does not take into account the angle of its inclination with the above constant movement. How to solve it?
More specifically, the question is how to calculate the vector directed directly in front of the character, taking into account the rotation (if anything, everything is in 3d):
5ecbbf74503c2250345042.png

PS knows) because the movement happens all the time, not just when a key is pressed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nwynther, 2020-05-25
@nwynther

something like this
this.speedX = Math.cos(angle/180*Math.PI)*10;
this.speedY = Math.sin(angle/180*Math.PI)*10;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question