Object Move

hi everyone
i have had difficulty with this so i was wondering if you can help me

i wanted to create liftable object in blender ge such as the way you can
move objects in penumbra and amnesia

im not all good with python so logic bricks would be better but so far
i can only collide a cube to an empty which disables its rigid body
and tracks it to the empty but this only makes it rotate so i want to
know if anyone can help me

thanks :slight_smile:

Hi Glitch999,

if you want your object to behave as if you pulled from where you clicked it,
that might be quite difficult to achieve, youā€™d most certainly need python for that.

Anyone correct me if Iā€™m wrong, but I believe the only way apply a force to an object
which can result in rotational shifting is to use applyImpulse(), since you can
specify where on your object to apply the impulse to (warning: Iā€™ve never tried it before).

Now youā€™d need quite a sophisticated script to apply the impulse depending on the objects
and your empties position, since you want it to stop after a while (as if you had friction).

However, if you only want your object to copy the position of your empty,
write a small and cute script to parent your object to your empty.

brick: collission with empty-> brick: python script.

python script:

import bge

cont = bge.logic.getCurrentController().owner #gets your hit object
empty = bge.logic.getCurrentScene().objects[ā€˜your_empty_nameā€™] #gets your empty object

if bge.grabbeditem == None: # if global variable ā€˜grabbeditemā€™ is None, eg you dont hold anything [indenthere]cont.setParent(empty, False, True) #parent your hit object to your empty[indenthere]bge.grabbeditem = cont #and set your ā€˜grabbeditemā€™ to the item youā€™re holding
*

 messes up linebreaks, what the hell?

This script grabs your item on collission, and sets it so you can't grab another item.
However, you'd need another script to release the item again ([removeParent()](http://www.blender.org/documentation/blender_python_api_2_57_release/bge.types.html#bge.types.KX_GameObject.removeParent)) and to set your bge.grabbeditem to None again.

It would make a lot of sense to use a mouse sensor for triggering the script,
so you could simply grab and release again by clicking.

Thereā€™s no need to import bpy - thatā€™s not a BGE Python module.

Whoops, thanks, fixed it.

im sorry but im completely baffled at what you saidā€¦
did you want me to import the script because i cant get it to workā€¦

Oh, sorry if I confused you. Savartā€™s code seems like itā€™ll work, but I think the forum software mangled it. This should work:



import bge

cont = bge.logic.getCurrentController().owner #gets your hit object
empty = bge.logic.getCurrentScene().objects['your_empty_name'] #gets your empty object

if bge.grabbeditem == None: # if global variable 'grabbeditem' is None, eg you dont hold anything 

     cont.setParent(empty, False, True) #parent your hit object to your empty

     bge.grabbeditem = cont #and set your 'grabbeditem' to the item you're holding

i was still confused by all this python (i know om dumb xP)

however playing around with bricks ive found a way of doing thisā€¦although when picked up the object is stationary
but this is still good it does return to a rigid body when you let go of the left click
thank you all for helping but i think its my lack of phython knowledge thats the problemā€¦:frowning:

ok now ive just decided im not happy with my setup (i know xD)

sooā€¦ if i post the blend? could someone please implement this python and then i can see how it was used and hopefully
help my understanding in python (slightly)???

here it is:
Base.blend (247 KB)

(yes i know its very messy and simple butā€¦ its what i got)

and thank you all for your help even if I didnt understand it :slight_smile:

Iā€™ll prepare a minimal blender file for you in the next hour.

Ugh, blender 2.49 ;). Iā€™m going to do a new file.

Alright, I downloaded the blender 2.55 mousescript,
and implemented the mouse grabbing.
The python code should be self-explanatory.

test.blend (749 KB)

Adding the velocities is not mandatory, but fun if you like throwing things around.

omg im sorry but i cant seem to get your file to work (i even tried it in blender 2.55) it it doesnt seem to be picking anything up

also i use the older version as i find the new version (even more) confusing to use so even if you got it to work i probably wouldnt be able to use it sorry but is it not possible to have it done with blender 2.49?

Wow, this is pretty ridiculous. Yesterday it was working fine, now I get tons of indentation/character errors.
Blender canā€™t handle the awesomeness that are comments after multilined ā€œif-conditionsā€ :(.

Iā€™ll take a closer look later.

thank you in advance for any trouble :slight_smile: