Changing X but not moving on the screen? (SOLVED)

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

Console:


I know im asking too many questions dont kill me please

Try this script

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.

TeleportExample.zip (2.3 KB)

1 Like

Your code looks ok, but you’re only teleporting at 0.06 pixels per update :smiley:

Need moar teleport, or a higher value in your distance vector.

3 Likes

You could replace the ‘400’ with variable and change it higher or lower, see the difference

1 Like

thanks people Ill try all of them

is there a way that it will not move there but appear there?

You can set the position in the init() function. That will cause the game object to appear at the set location. For instance:

function init(self)
    local start_pos = vmath.vector3(100, 100, 0)
    go.set_position(start_pos)
end

alright thanks will try that

okay I have tried this approach

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 :slight_smile:

1 Like

btw why dont the devs make a discord server for the engine or something?

We already have a slack channel if that’s what you’re after?

I wanted discord but slack good enough I guess :slight_smile:

1 Like
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)

Nevermind Fixed Sorry