My new code is a mix from the snake tutorial I feel like that’s easier to understand as it uses a self.alive command. I have mixed it in with the command from the runner tutorial. I’m not a programmer so sorry if I’m having trouble understanding it.
function init(self)
msg.post(".", "acquire_input_focus")
self.start_position = go.get_position()
self.moving = false
self.input = vmath.vector3()
self.dir = vmath.vector3(0, 1, 0)
self.speed = 300
self.alive = true
end
function final(self)
msg.post(".", "release_input_focus")
end
function update(self, dt)
if self.moving then
local pos = go.get_position()
pos = pos + self.dir * self.speed * dt
go.set_position(pos)
end
self.input.x = 0
self.input.y = 0
self.moving = false
end
function on_input(self, action_id, action)
if action_id == hash("up") then
self.input.y = 1
elseif action_id == hash("down") then
self.input.y = -1
elseif action_id == hash("left") then
self.input.x = -1
elseif action_id == hash("right") then
self.input.x = 1
end
if vmath.length(self.input) > 0 then
self.moving = true
self.dir = vmath.normalize(self.input)
end
end
function on_message(self, message_id, message, sender)
-- Handle collision
if message_id == hash("contact_point_response") then
local newpos = go.get_position() + message.normal * message.distance
go.set_position(newpos)
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("reset") then
self.velocity = vmath.vector3(0, 0, 0)
self.correction = vmath.vector3()
self.ground_contact = false
self.anim = nil
go.set(".", "euler.z", 0)
go.set_position(self.position)
msg.post("#playerCS", "enable")
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("trigger_response") then
if message.enter == hash("danger") then
self.alive = false
msg.post("#playerCS", "disable")
msg.post("#playerCS", "reset")
end
end
end
The runner tutorial is hard to apply to mine because it forces the game to spawn in objects and when you die, it forces it to despawn the objects. The only thing I want to do is just move the character back to where the character starts the level once the character crosses a trigger zone