Sprite Disappears

Hello,
My player sprite disappears when I set the game object’s position from an external location. Here the player is supposed to be moved when it hits a trigger. That’s the whole trigger’s script.

local player_pos
function on_message(self, message_id, message, sender)
	if message_id == hash("trigger_response") then
		if message.other_id == hash("/player.go") then
			player_pos = go.get_position("player.go")
			go.set_position(vmath.vector3(725, player_pos.y, 0), "player.go")
			-- Commenting out above line and it doesn't disappear
			-- Tried this: go.set_position(vmath.vector3(725, 150, 0), "player.go")
			-- Replacing player_pos.y with an absolute number had no impact
		end
	end
end

Thanks to toggle_physics_debug I was able to see that my player was still working fine (fully functioning and go.set_position worked), it just doesn’t have a sprite anymore.
There is no line of code in my player script which can disable the player sprite as far as I know. I searched the file after “disable”, no line could disable “.” or “player.sprite”. Additionally I have on_message disable release_input_focus, I still have input focus and I usually disable everything via the game object not the sprite component.

How about player_pos.z? It could be so that you are moving it outside of the orthogonal rendering box. If you see the player there with physics then that’s most likely the case.

Do this:

local player_pos = go.get_position(message.other_id)
player_pos.x  = 725
go.set_position(player_pos, message.other_id)

Also while at it, I would move the target position to

go.property("teleport_pos", vmath.vector3())

function on_message(self, message_id, message, sender)
  -- teleport objects that walk inside
  if message_id == hash("trigger_response") then
    local pos = go.get_position(message.other_id)
    pos.x  = self.teleport_pos.x
    pos.y  = self.teleport_pos.y
    go.set_position(pos, message.other_id)
  end
end
2 Likes

This is very likely the case. The default render script has a z-range of -1 to 1.