Moving an object

Always quicker to ask here when I can’t figure it out;

ok my problem is not as simple as it sounds.

I have a player, and I have an empty mesh, I want to press a button and have the player instantly move/teleport to the coordinates of the empty mesh.

how to?

First, what do you mean a empty mesh, do you mean a empty object, a object with no mesh or a mesh with a fake user.
If it is one of the first two you will just have to use python and the function object.worldPosition, if it is a fake user I don’t think it has coordinates.

import bge

owner = bge.logic.getCurrentController().owner
scene = bge.logic.getCurrentScene()


#somehow put your key into here eith KX input or sensor:
key =  . . .
emptyMesh = scene.objects["empty mesh"]

if key:
    owner.worldPosition = emptyMesh.worldPosition

I should have been clearer, this is in 2.49b.

object.world position sounds like a good start.

indeed, also very helpful, thankyou I think i can adapt that code to 2.49b ese

both of you have been very helpful, and I thankyou. I thought this sorta thing might have some sort of way to do it through the logic bricks (something I wasn’t seeing).

very well though, seems I’ll have to do a bit more scripting.

again thanks.

actually let me tell you the full usage of this, I want to use it for spawning enemies and or the player at different places. (like in the instance that you just start the game your character starts from a specific point)

would the code you gave be the most addequate way to do such?

Oh, for 2.49b? Here’s code for that!

import GameLogic as gl

obl = gl.getCurrentScene().getObjectList()
cont = gl.getCurrentController()
own = cont.getOwner()
sen = cont.sensors
act = cont.actuators

player = obl["OBPlayer"]

player.setPosition(own.getPosition())

It’s a basic template. You’ll need to put this on the empty that you want to snap the player to. And the player needs to be named “Player” for this specific script.
(Sorry if you know all this. Just wanted to help.)

very good, and thanks, I knew most of these before, get and set position thats what I needed, mercy I have used those two before why couldn’t I remember get and set?

oh well thanks for the memory! :wink: