2
$\begingroup$

I'm updating an objects location using a Simple Motion Actuator. I see it move on the screen.

In Python I want to get the objects' current position.

scene = bge.logic.getCurrentScene()
obj = scene.objects['Sphere.002']     # The object the actuators are defined on

obj.position
obj.worldPosition
obj.localPosition

I've tried these three methods of the object, but all of them only show the original position of the object, not the current position based on the changes made by the logic bricks.


Here's another example of what I'm doing wrong, it seems to be the same problem.

I have a text object, I've defined a text game property that I increase or decrease with a keyboard sensor. When I print the value of the text it only prints the original value of 0.5 not the value I see on the screen.

enter image description here

print(bge.logic.getCurrentScene().objects['mytextobject'].text)

This always prints the original value, not the value that is updated from the logic bricks. This must be a trivial error, but I can't figure out what to do. I've looked at all the properties of the scene.object and I don't see anything that looks like it might give me the expected result.

$\endgroup$
2
  • $\begingroup$ What changes have you made?. obj.worldPosition = current world position. Maybe 'Sphere.002' never move. Please add some images. $\endgroup$ Nov 28, 2017 at 1:13
  • $\begingroup$ Be aware controllers get executed BEFORE the active actuators run. $\endgroup$
    – Monster
    Nov 28, 2017 at 6:06

1 Answer 1

1
$\begingroup$

When are you reading the value? If you've assigned it to a variable, it might be reading the initial value, and ignoring any updates.

You'll need to update the value periodically. Possibly using an Always sensor, with a skip, if desired. Or at certain times within the game; collision with another object, for instance.

You may need to access appropriate coordinate within it's location vector: obj.pos.x

Location

$\endgroup$
1
  • $\begingroup$ It's during the execution of the game that I don't see the changes. I print this value out constantly: bge.logic.getCurrentScene().objects['Sphere.002'].position.z and the object Sphere.002 moves on the screen in response to my keyboard (using logic bricks). But it always prints the same original value of 3.25, where it starts on the screen. $\endgroup$ Nov 28, 2017 at 17:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .