Controlling object motion via python?

I’m trying to find a way to control an object such as an airplane, using a joystick. I have no problem getting data from the joystick, but I don’t know how to then move an object in the scene.

Python is familiar territory for me, but I haven’t used it inside blender much. An API reference would be as welcome as a tutorial on realtime scripted motion…

Help? :slight_smile:

You can use a motion actuator for movement.


c = GameLogic.getCurrentController()  #Gets the controller
motion = c.getActuator("motion")  #Controller connected to a motion actuator with that name

#Now you can access the forces on the motion actuator with these functions:
motion.setDLoc(x,y,z,l)  #corresponding to those values on the actuator
motion.setForce(x,y,z,l)
motion.setLinearVelocity(x,y,z,l)
motion.setDRot(x,y,z,l)
motion.setTorque(x,y,z,l)
motion.setAngularVelocity(x,y,z,l)

#At the end of the script, you will want to APPLY or FIRE the actuator, you do this with this command:
GameLogic.addActiveActuator(motion,1)  #The 1 tells it to turn the act on, a 0 means turn it off

#Blender automatically imports GameLogic for you, so you don’t have to import it in the script, but it doesn’t hurt anything if you do