Hi everyone!
I want to rotate a square with the left and right buttons in de z axis. I want to rotate it without a maxim angle.
I’ve done this but is not what I want, because it has a maximum angle and it dosen’t rotate constant!
– Constants
local turn_speed = 0.05 – Slerp factor
*local max_steer_angle_left = vmath.quat_rotation_z(math.pi ) *
*local max_steer_angle_right = vmath.quat_rotation_z(-math.pi ) *
function init(self)
- – Acquire input focus so we can react to input*
- msg.post(".", “acquire_input_focus”)*
- – Some variables*
- self.steer_angle = vmath.quat()*
end
function update(self, dt)
- – Set the game object’s rotation to the direction*
end
function on_message(self, message_id, message, sender)
- if message_id == hash(“left”) then*
-
-- Interpolate the steering angle.*
-
self.steer_angle = vmath.slerp(turn_speed, self.steer_angle, max_steer_angle_left)*
-
go.set_rotation(self.steer_angle, "Square")*
- elseif message_id == hash(“right”) then*
-
-- Interpolate the steering angle.*
-
self.steer_angle = vmath.slerp(turn_speed, self.steer_angle, max_steer_angle_right)*
-
go.set_rotation(self.steer_angle, "Square")*
- end*
end
function on_input(self, action_id, action)
- if action_id == hash(“left”) then*
-
msg.post("#", "left")*
- elseif action_id == hash(“right”) then*
-
msg.post("#", "right")*
- end*
end
Thanks in advance!