Detecting and reassigning LocXYZ

I’m just playing around with the games engine a bit, and I’m thinking this should be very simple, but I can’t find the right actuator, properties etc.

I have this simple character which I’ve made move with arrow keys (through logic blocks). When he reaches the edge of the playing field, he falls of the grid.

Is there a way I can reset his position (X,Y,Z coordinates) when he falls off (e.g. Blender detects that Player has a LocZ <= -3 ?

Basically, what I want to do looks something like: IF Player.LocZ<=-3 THEN {Player.LocX=0; Player.LocY=0; Player.LocZ=2} …or something to that effect.

I would prefer a logic block way of doing this rather than python, but am up for anything clearly explained. (e.g. if python is needed, how do I insert / run it in-game?)

Hope someone can help in good speed (please).


simplemoves.blend (77.4 KB)

o = GameLogic.getCurrentController().owner

if o.position[2] &lt; -3:
     o.position = [0, 0, 2]

Paste it into the text editor in Blender, replace the five spaces with a tab, add an always sensor connected to a python controller on the object you want, and type in the name of the script (it defaults to Text)


Reset.blend (131 KB)

Thanks - that was certainly in good time!

Is there no way I could do this with logic blocks?
As python, how do I put the code into my game?

I accidentally posted before I was finished, I’ve updated my post and attached an example.

Thanks. Your example works, but when I try to use the script myself it does not.
Any idea why? I am using 2.5, though your example does work… just not when I try to implement the script to my own version (keeps falling)


simplemoves2.blend (76.4 KB)

A common logic used for that is to position a large plane at z=-3 and detect collision with this plane (which will occur only when object falls)

True, I’ve done that, but apart from a level restart, how do you reset the position of the player to a specific ZYZ point? Would you normally use a constraint actuator?

I’m still wanting to know why the script offered doesn’t work in my own version. Been staring at it.

It seems like a bug of the “always” sensor to me. The script is called only once when starting the game and not at each logic step.

You can use the Location Constraint to move the object to a location.


Found it! Thanks - you were in the right place. The reason it wasn’t working was because I hadn’t activated “true level” pulse mode…

Seems that unless a trigger is event driven (e.g. a keypress to set it off) then it needs to be pulsed and this unlocks it. I’m not sure if I’m 100% on why it’s needed or why you would not want “always” to be always though.

Still, with that strange thingamie pressed, the script kicks in and is now working.



simplemoves3.blend (79.6 KB)

Read this to understand how sensors work.

Python is important when you go for scripting. The logic bricks provide a quick and simple way to add logic. If you want to do more than the simple stuff you will need to do some scripting.

Anyway, here is a Non-Python solution:

Add an IPO to the player. You just need one keyframe.
add this to your player:

collision (property: a property of the “out of play” plane) -> and -> IPO actuator play 1-2

What happens:

  • If the player falls from table, it collides with the below plane
  • the collision sensor recognices the collision with that plane (because of the property of the plane)
  • and triggers the AND controller with True pulse
  • which activates the IPO actuator
  • The IPO actuator sets the pose from the IPO curve (initial position)

Because of the changed position there is not collision anymore

  • The collision sensor triggers the AND controller with False pulse
  • which deactivates the IPO actuator
  • That let the player freely move around without the IPO applied.

This method can be used to reset the orientation as well (loc Keyframe + rot keyframe). You can even have an “appearing” IPO like scaling from 0.0 to 1.0 by playing more than two frames.

I hope it helps

Thanks. I RTMFed the page you gave me but it’s just confusing me… I think I got most of it but the diagrams look weird and I’m still not sure what the tap thing is about.

I don’t understand why you’d choose to use IPO curves. I know what they are in as much as I’ve used them for driven keys in my rigging, though for the sake of the process relying on a big net to catch the player as he falls, are they any better than the afore suggested constraint? (apart from the ability to key a whole range of other things of course).

I don’t see why Blender has actuators for altering forces of various kinds (additive Loc, Force and LinV) and yet does not have a dedicated actuator / sensor pair for direct access to an objects realtime LocXYZ values (except for the constraint actuator), therefore forcing users to use more complicated methods such as the IPO curves or at least learning Python. I’m sure the devs have their reasons or not making a direct position sensor… I just don’t get it.

I’m concluding that sensors and actuators are very limited, but I don’t understand why they have to be.