S
S
Space Around2020-04-24 18:40:34
Physics
Space Around, 2020-04-24 18:40:34

How to implement object movement?

There is an object that must move in a given direction in 2d, the speed with which this object must move and the angle (the direction of movement is 0-360 degrees) is given. We need to implement movement using a function that takes 2 parameters X and Y.
My course of action:

  • 1) decompose the speed into two projection speeds
    Vx=V*cos(alpha); Vy=V*sin(alpha)
  • 2) find the position of the object at a certain moment
    x=Vx*t*cos(alpha); y=Vy*t*sin(alpha);
  • 3) I substitute the resulting coordinates into the function (this function is called once every t seconds, so the variable t changes)

The problem is that the object is moving in the wrong direction. How so?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sofronov, 2020-04-24
@viksnamax


x = x0 + V * cos(alpha) *
t

U
uvelichitel, 2020-04-24
@uvelichitel

x += V*cos(alpha)*t

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question