how do i pick stuff up

i have some crates sitting around the room
i have an empty parented to my character
when i have the mouse over the desired object and press “E” i want it to snap to and be parented to the empty

how would i do this? or is there an easier way to simulate picking things up
thanks

this might work,

give the crate a camera actuator (with the object it follows being the empty) with the minimum and maimum set really low and close together,

but these logic bricks will be kinda confusing so ill set them up for you in a blend and then give you the blend, then you can just copy them to your object

http://www.4shared.com/file/33448485/fa828569/crate.html

well it works…kinda, after you pick it up it slowly falls down,
and i still have to make a ray so you can only pick it up when your facing it, unless you already know how to do that ill do that too

eh, thanks but that aint gonna work. it tracks to my character but it slams into him and constant force is applied to him making things sorta weird.

what i was thinking is maybe do it like a switch weapon thing, like this:
crate
if cursor over+if press E------>(cont)-------> send message+end object

empty
if get message------> (cont) ------> add object “pickedupcrate”

i would have “pickupcrate” in another layer, this idea works all except when the “pickedupcrate” is created it doesnt track to my empty. if i could figure out how to make the crate in the other layer track to my empty upon creation until a drop key is pressed, then i would have solved my problem.

for this to work the empty has to be out in front of him, but it doesn’t realy matter since it goes down slowly anyway

may be you could hold shift and then select both the layers, and then parent the crate to the empty that way:confused:

i tired that, but it dont respond to the parent

i had another idea. see im gonna have more than just crates in my game that my character can pick up, i plan to include guns and lamps and such.

one way i figure would be useing overlays

Crate
If mouse over+if press E—> (cont)–> end object+ add overlay “crate”
the only thing that sucks with this idea is that you would have to make a scene for every stuipid object in the game and said object can no loger receive light (very important to my game)

another way would be to put every possible pick up-able object’s shell in my game on my empty at the start, but make them invisible. then as i collected them they would become visible and when i pressed the realease i would simply add the object back and make it invisible again.
but this is bad because it would eat up my frame rate, i think…

http://www.4shared.com/file/33451454/7843ad88/_2__crate.html

i got my first idea to work, i just had to take out the gravity
but im not sure how this will work with bumping into things : /

just make sure the empty is out infront of the player and i think it should work

You can make the crate work after adding it as a new object by doing this:

Attach a message actuator to whatever adds the new object. In the subject field say ‘up’.

Have a message sensor looking fut ‘up’ attached to the object and the camera/player. And have it send the first ‘up’ message to the object.

It works like that in the ‘get em’ game in the WIP section. If you will have it move up, down etc, more than once then you will need to add more properties to shut if off fromt he player/camera/ or from the object itself.

Hope that helps

If you want to use python:

    • have an empty in front of your character (“liftable” object will be placed here)
    • Create a “ray” sensor on an empty in front of the player (name it “ray”) and have it look for the property “lift”. Make sure it’s pointing it’s “Y” axis away from the character. Also, create an keyboard “e” sensor and name it “eKey”. Combine both sensors into a python controller.
    • give the “liftable” object the property “lift”.
    • put this text into a python script:
cont = GameLogic.getCurrentController()
own = cont.getOwner()

ray = cont.getSensor("ray")
eKey = cont.getSensor("eKey")
object = ray.getHitObject()

if eKey.isPositive() and if hasattr(object,"lift"):
     object.setPosition(own.getPosition())  #make sure this line is in 1 tab from the last line
    • link the script to the python controller on the empty.

That should work for you. If you want to throw the object, then it gets a little more complicated.

~~Stu

what is hasattr()? i’ve never seen that before…

You may also have to suspend dynamics on the hit object in the script, otherwise it will be affected by gravity even with setPosition. You might also need to add getOrientation to the empty and setOrientation to the hit object to make the held object face the same direction as the empty. Don’t trust my python skills, or lack of python skills, though. Stu can help you better than I can.

I’m really not sure at all, but I thought that hasattr() had to do with another input needed to initialize the script. I’ve seen it used before.

happy new year!

The “hasattr()” function is short for “has attribute”. So if you write: if hasattr(object, “something”), then it checks to see if “object” has the attribute (in this case a property) “something”.

~~Stu

Stu: is there a getattr() or something that lists the properties an obj has?

download this python file and put it in your blender directory.
Type this into one file in blender:

from APPLE2 import initGame,ragdollConstraint
own=initGame()['own']
cont=initGame()['cont']
ray=cont.getSensor('ray')
lmb=cont.getSensor('lmb')
if ray.isPositive() and lmb.isPositive() and own.time > 0.1:
    ob=ray.getHitObject()
    if ob.getPhysicsId() != 0:
        own.const=ragdollConstraint(own,ob,[0,0,0])
        own.time=0

of course, you’ll have to add the “ray” and “lmb” logic bricks and the integer property “const”. Connect those two logic bricks to the python controller.
Type a new file:

from APPLE2 import initGame,removeConstraint
cont=initGame()['cont']
ray=cont.getSensor('ray')
lmb=cont.getSensor('lmb')
if ray.isPositive() and lmb.isPositive() and own.time > 0.1:
    ob=ray.getHitObject()
    removeConstraint(ob.const)
    own.time=0

Connect the same two sensors to this NEW python controller. This should work. Holler if it doesnt.
P.S. you might want to change it to a point-to-point constraint. change the ragdollConstraint() function to p2pConstraint() and it should be fine

???:confused:

wow, thanks but i have no idea whats going on anymore. i already changed how my whole game play style is gonna go, and its lots of fun! in fact its more fast paced and origional than what i wanted to intially do. i can even include far more puzzles this way, but i dont want to say what it is cause i dont want my idea to be stolen/spoiled.
but thanks for the help, the big problem with the pythons i got was that my game has already come along a bit in development so i would almost have to change everything to make it apply with my game and the other sensors around it.
but like i said, i found out something really cool instead.
thanks anyway, at least now there is some code out there for someone else.