This can’t be hard. I just want to get the position of an object, but have the coordinates be defined to three separate variables: x, y, and z. Try as I might, I could not find a solution on the internet, and my own efforts led to the console telling me that none of my variables were defined. Any help would be appreciated.
Look at the example script( text editor: file|script templates|object ) and if that doesn’t help post the code you’ve tried so far. Or read the python scripting reference on the wiki.
Umm, pretty simple… put into your python controller the name of the script. Then, for the script, type:
cont = GameLogic.getCurrentController();
obj = cont.getOwner();
x = obj.getPosition()[0];
y = obj.getPosition()[1];
z = obj.getPosition()[2];
Hopefully, that’s it.
I worked it out. It was much easier than I was making it, I just needed a quick brake.
This prints the z-position:
pos = own.getPosition()
z = pos[2]
print z
Real simple, I was just being dumb. For anyone who wants to know, pos[0] is for x, and pos[1] for y, I just needed the z-value for altitude. Thanks for the help, Caveman.
Edit: Joeman16, you posted just before me. That was what I was looking for. Thanks.