Rotate sprite according to velocity of game object

What I am trying to do is similar to breakout game in place of ball bullet is their. When bullet will hit the walls bullet sprite has to face in direction of velocity vector.

Frame%205

If the possible velocities are few (like multiplo of 45 degrees) then you can use some if-else’s. Otherwise you have to use arctan, a trigonometric function. Try googling it, it’s very simple.

2 Likes

You can probably use vmath.quat_from_to:

local v1 = vmath.vector3(1, 0, 0) -- you may need to change this depending on which direction your original bullet sprite is facing
local v2 = vmath.normalize(velocity) -- assuming you describe your velocity as a vector3
local rot = vmath.quat_from_to(v1, v2) -- get rotation as quaternion
go.set_rotation(rot)
3 Likes