Rotate Object (SOLVED)

Hello,

I have this code in my game to rotate a gun:

if self.click then
	   self.angle = self.angle - 1
	   
	   local rad_angle = math.rad(self.angle)
	   local rot_angle = vmath.quat_rotation_z(rad_angle)	
	   go.set_rotation(rot_angle, self.line)
   end
   
	if self.angle < -90 then
		self.angle = -90
	end

but my gameobject is rotate 180 degrees in the editor and with vmath.quat_rotation_z I lost my rotation y.
how can rotate only z component?

Sorry for my english.
Regards.
Maxi.

You could make the Z rotation relative to some base rotation. You can add together quaternion rotations by multiplying them. So if you store the original rotation, then in your click code do:

go.set_rotation(self.base_rotation * rot_angle, self.line)

Which should work, depending on your specific use case.

3 Likes

Hi,

thanks for your reply, working great!

2 Likes