
[ad_1]
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
13 times
Given a Vector2(x,y)
that represents an object’s velocity, like so:
let angle = Math.PI / 2;
let speed = 500;
let velocity = new Vector2();
velocity.x = Math.cos(angle) * speed;
velocity.y = Math.cos(angle) * speed;
How can you retrieve the speed?
let angle = Math.atan2(velocity.y, velocity.x);
// let speed = ???
CAOakley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
\$\endgroup\$
0
Was able to get the answer as:
let speed = Math.sqrt(velocity.x ** 2 + velocity.y ** 2)
CAOakley is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
\$\endgroup\$
0
default
[ad_2]