Moving object with python script?

Hi! I was wondering if there is a script or a tutorial on how
to move an object in game using python?

also, if there is a script or way to accomplish this, would it
go along with the games gravitational forces?

ex.) say i’m moving the object across the X axis on a plane,
the plane also goes downhill, will it go down the hill?
or will the object just move on the X axis?

UPDATE: also, is it possible to be able to move softbody objects in game? Thanks!

-Dylan

This tutorial can hopefully get you started :slight_smile:
http://www.tutorialsforblender3d.com/GameDoc/Movement/Movement_Script_1.html

its for 2.49, conversion to 2.5 isnt too hard… although maybe not a good idea while learning!

hi! Actually I run 2.49 so I am in luck! Also, I’ll take a look into the tutorial.
Thanks a lot!
-Dylan.

sorry for double post, but do you know if there is a way to move a softbody object in game using the keyboard? thanks

UPDATE: sadly, that Tutorial was not what I was looking for. But thanks anyhow

I’m still looking for a way to do this, any help appreciated.

-Dylan.

if your ground is ‘static’ and your object/character is some kind of body (dynamic rigid or soft) then adding FORCE to an axis should move you in that direction, and obey up / down hills, falling from a cliff with gravity etc.

i have attached my simple 2.5x demo, although it solely uses logic bricks.

to the best of my current knowledge, ‘using python’ still involves using the logic bricks, for detecting your key presses etc etc, and initialising the script, you just modify the actuators etc or manipulate the movement etc from the script instead of actually using all of the logic gates.

Attachments

softbody.blend (569 KB)

ooh ok! I checked out your blend file, for some reason hitting ‘P’ key wouldn’t start the game for me,
but i remade what you did, and it does work. Thank you!

UPDATE: Now, i cannot quite seem to be able to turn the character with the arrows. (left and right) any idea’s?

I don’t believe soft body objects supports either moving an object using obj.position, or rotating an object with dRot or obj.orientation (I’m not sure about dRot or other rotation methods, though). If you need to rotate an object, use:

import math

x = math.cos(moveangle) * movespd
y = math.sin(moveangle) * movespd

motion.linV = [x, y, 0.0]
cont.activate(motion)

or something like that to move on a rotational value you can change (change moveangle to move the object).