This article describes a way to „pick and move objects“ in Blender Game Engine.
Unfortunately a lot of published code is not working with the current version of Blender or depends on specific objects within the scene.
I wrote the code to try some 3D Collision Shapes. In order to do that, i wanted to have the objects movable to see how they interact with other objects.
Let me know if you see any improvements and leave a comment if it’s useful for you.
The code does the following:
- pick an object with left or right mouse click
- move it as long as the mouse is clicked, release it otherwise
- move on x/y plane with LMB, move on y/z plane with RMB
Currently i’m fine with moving them with 3DOF, so i can move them in X,Y and Z direction.
I have written this little script, which is triggered by MouseOverAny, Left Mouse Button Click and Right Mouse Button Click.
I’ve assigned the sensors to the camera, which i thought is probably the only object that will stay within the scene.
import bge cont = bge.logic.getCurrentController() LMB = cont.sensors["LMB"] RMB = cont.sensors["RMB"] if LMB.positive | RMB.positive: mouseOver = cont.sensors["MouseOver"] obj = mouseOver.hitObject mouseX = mouseOver.hitPosition mouseY = mouseOver.hitPosition mouseZ = mouseOver.hitPosition if LMB.positive: obj.position = mouseX obj.position = mouseY if RMB.positive: obj.position = mouseY obj.position = mouseZ
The assignments can be seen here:
As i’ve received some good information through YouTube videos, let me know if anyone is interested in seeing some videos from Anagram as well.
I’ve added a linked object and want to move it. How can I do?
If you want to move linked objects, you have to make them a proxy.
CTRL + ALT + P
will do so.