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

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

\$\begingroup\$

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