co-ords of an object?

How would i get and store the X, Y, Z co ordinates of an object in a script, or each individually, for example:

xPos =

yPos =

zPos =

the reason to do this is so that i could copy one or more of one objects co-ords to another eg:

cube(xPosition) = sphere(xPosition)

any help appreciated, thanx

You can do it like this:

from bge import logic

scene = logic.getCurrentScene()
objects = scene.objects
obj1 = objects['firstObjName']
obj2 = objects['secondObjName']

#apply first object's position to second object's position in X axis
obj1.worldPosition.x = obj2.worldPosition.x

#apply first object's position to second object's position
obj1.worldPosition = obj2.worldPosition

This may work!:wink:

exactly what i was looking for thanx! one more question, how would i measure the distance from one point to another? so for example:

object.worldPosition.x to object2.worldPosition.x

or between any 2 points?

object.getDistanceTo(object or vector)


Hi! A bit too late:

(magnitude method too)

Thanx guys, exactly what i needed! :slight_smile: