I’m making a simple 3d first person pong and i need to set the balls speed to a constant, but getLinearVelocity includes both direction and speed, how would i get the speed part of the vector,set it, then recombine it with its direction then use that to do setLinearVelocity.

so pseudocode-

direction=getLinearVelocity-speed

speed=getLinearVelocity-direction

speed=//certain constant

setLinearVelocity=speed+direction

The linear speed is the magnitude of the velocity vector. The function is called length() in Vector3f.

To set a new linear velocity, use normalize() to get a vector of length 1.0 (“unit length”) that points in the same direction, then multiply() with the new desired speed.

Splitting a vector into length and direction is often not necessary though. For example, to double the speed, simply multiply() the vector by 2.0.

1 Like

thanks, i understand what you are saying now just for curiousity how do you split it

“split” = process length and direction separately

i.e. the split is length() and normalize()