Hi all,
i have this script from tutorial. all works fine. but now i want to rotate the spaceship und oly in the direction he looks up i want to speed up not backwards … actually the movement works fine but right,left,down,up all the same
how can i do this?
go.property("max_speed", 800)
go.property("acceleration", 800)
local ACCELERATE = hash("ACCELERATE")
function init(self)
msg.post(".", "acquire_input_focus")
msg.post("camera", "acquire_camera_focus")
self.velocity = vmath.vector3() -- [1]
self.input = vmath.vector3()
end
function update(self, dt)
if vmath.length_sqr(self.input) > 1 then
self.input = vmath.normalize(self.input)
end
local acceleration = self.input * 200 -- [2]
local dv = acceleration * dt -- [3]
local v0 = self.velocity -- [4]
local v1 = self.velocity + dv -- [5]
local movement = (v0 + v1) * dt * 0.5 -- [6]
local p = go.get_position()
go.set_position(p + movement) -- [7]
self.velocity = v1 -- [8]
self.input = vmath.vector3()
end
function on_message(self, message_id, message, sender)
-- Add message-handling code here
-- Remove this function if not needed
end
function on_input(self, action_id, action)
if action_id == hash("up") then
self.input.y = 1 -- [1]
elseif action_id == hash("down") then
self.input.y = -1 -- [1]
elseif action_id == hash("left") then
self.input.x = -1 -- [1]
elseif action_id == hash("right") then
self.input.x = 1 -- [1]
elseif action_id == hash("click") and action.pressed then
print("CLICK!")
end
end
function on_reload(self)
-- Add reload-handling code here
-- Remove this function if not needed
end