0
\$\begingroup\$

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 = ??? 
\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

Was able to get the answer as:

let speed = Math.sqrt(velocity.x ** 2 + velocity.y ** 2)
\$\endgroup\$
0

Not the answer you're looking for? Browse other questions tagged .