I´m trying to code some Python into a Game Blender menu and got into a few newbie´s brickwalls.
If someone could help me code this…
I have a menu (a map) with some 100 hot sopts (planes). When the user clicks into one, the camera gets set to some position elsewhere.
I was thinking into coding it like this:
|Hotspot |---------| Python script |
all hotspots are linked to the same script.
The code would check the hotspot name and based on that get the position and orientation of a similar named Empty on the scene.
Like Hotspot.somename would check for Empty.somename properties.
Then the script set the the Camera empty to the position and orientation of the checked empty.
The problem is:
I dont know how to set some spefific obj pos and ori. I can only do it to a “own” right now…
How do I process the clicked name (Hotspot.somename to strip the first 7 letters and compose the name Empty.somename?
Prior to 2.34, no you can’t. I haven’t experimented much with the new api, but I think you can get objects through the scene module. Check out the official api documentation:
Perhaps a simpler way of doing this is to define the camera position/orientation across a series of frames using an IPO curve. A certain frame would define the camera position/orientation at a certain empty (though you wouldn’t need empties with this system).
You then use an IPO Property logic brick to set the camera’s position.
Andy, actually that´s the way I have it coded right now, but since I have hundreds of hotspots and IPO, it´s getting pretty complicated to administer. So I thought about this empty´s way. It would make it very clean to handle.
But I´m seeing this is not so easy (still I´m having a very good change to learn Python !!). Anyway, if this can´t be coded, I´ll go back to the IPO way, maybe integrating it in one Python script with a property IPO for all the hotspots (it´s separated and hard coded right now).
Why is that the last two blocks of code (#pos and #ori) output the same values for Old and New values ? Do I need some update command after the values are changed?
The behaviour of the scene is perfect. My curiosity is just these print commands not changing right away.
The game engine processes world stuff, then python, then world stuff, etc. So any commands that change the world wont take effect until the script ends. Such as setting an object’s position.