Grabbing and moving objects

Hi all

I am wondering on an approach to grabbing and moving objects around in my test map (from a first person perspective, using the FPS Controller that comes with Unity). I’m on Unity Pro btw, not sure if that has anything to do with it.

I have made a cube that sits in front of the camera on the FPS Controller. It will later be replaced by either a 2d or 3d hand with a “open” and “closed/grab” state.

Use-case: I have made a door that sits in a frame. The door has a hinge joint attached, and has a min and max variable. Well, basically it behaves like a door you can open and close by walking into it. What I would like to do though is to click on the door, and while the button is down the camera freezes its movement and instead the mouse controls the movement of the door. That is, I would like to apply forces to the door so that it moves around but are still constrained by the hinge joint.

Use-case 2: I have an object on the ground. I would like to click on it, and since this item is movable the camera moves around like normal, but this time the object is attached to the hand. While attached, if the object has several joints (like one of my objects, a suitcase) I would still like it to be able to have physics applied to it, meaning if its a rope it will behave like a normal rope would, collisions and all.

In the second use-case I thought about maybe attaching the object/pickup to the hand object through parenting…? Not quite sure on how to attack this problem, so if anyone have some experience I would love to hear about it!

theres quite a bit to it so i dont really have time to put detailed sample scripts, but you can tackle it this way and use the script ref to pick out the parts

you would have to use a “screenpointtoray” by an input.mousposition script http://unity3d.com/support/documentation/ScriptReference/Input-mousePosition.htmlto be able to click on the object.

then say for case 1 : youll have to use the mousebuttondown command and either make a variable or disable the other script to lock the camera, then on mouse up it switches back.

when the mouse is down you have to make it so if the mouse position moves up/down, left/right, it rotates the door in the direction you want.

this script is for touch, but with a little work it can prob be changed into mouse commands
http://unity3d.com/support/documentation/ScriptReference/Input.GetTouch.html

for the 2nd case: it is basically the same as above, but you have to edit how you want each item to react to the mouse motion. move? rotate? scale?
for objects like your briefcase with multi parts that you want to be able to swing, just make only the handle follow the commands, and if you set up your physics/rig properly the rest should follow automatically with the physics

hope this helps!

Thank you very much, I appreciate it! I’ll start working on it, and if it works out well I will release the code :slight_smile: