I’m trying to create a teleport but the X is changing but the player not moving on the screen
here is the code
function update(self, dt)
if self.teleport then
local p = go.get_position()
p = p + vmath.vector3(4,0,0) * dt
go.set_position(p)
end
self.teleport = false
print(go.get_position())
end
function on_input(self, action_id, action)
if action_id == hash("teleport") then
self.teleport = true
end
end
local function teleport(self, dt)
self.position.x = self.position.x + 400 * dt
end
function init(self)
msg.post(".", "acquire_input_focus")
self.position = go.get_position()
end
function final(self)
-- Add finalization code here
-- Remove this function if not needed
end
function update(self, dt)
if self.teleport == true then teleport(self, dt) end
go.set_position(self.position)
pprint(self.position)
self.teleport = false
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("key_space") then
self.teleport = true
end
end
function on_reload(self)
-- Add reload-handling code here
-- Remove this function if not needed
end
Make sure the object has input focus and that your action_ids are setup properly.
if self.teleport == true then
self.position = vmath.vector3(150,self.position.y,1)
go.set_position(self.position)
end
self.teleport = false
But the thing is I want to be able to use it more than once so I can but its just teleports to X = 150 but Ill try to move the character backwards so I think this thread is closed thank you all
local function teleport(self)
if self.action == true then
self.position = vmath.vector3(500, self.position.y, self.position.z)
go.set_position(self.position)
timer.delay(4, false, function(self, id)
go.animate(".", "position.x", go.PLAYBACK_ONCE_FORWARD, 298.735, go.EASING_LINEAR, 1)
self.action = false
end)
end
end
why does this code stops the player from being able to jump and gravity doesnt effect the player(Im sorry for jumping the thread or whatever its called its just looks pretty odd)