- Home /
move object to the hands of the user
i am trying to get a user to click an item and pick it up. i have done this. however when the user rotates the item it holds finds it hard to keep up with the user. my original idea was to replace the the empty game object i have in my controller with the item i clicked but i could not get this to work. if you have any ideas how id this it will be greatly appreciated. here the code used
private var itemHeld : boolean = false;
function Start() { //var heldItem = GameObject.Find("S2L- First Person Controller/held_Item"); var touchedItem; } function Update() { if(itemHeld == true) { var heldItem = GameObject.Find("S2L- First Person Controller/held_Item"); print("ciicked"+gameObject.name); gameObject.transform.position = heldItem.transform.position; gameObject.transform.rotation = heldItem.transform.rotation; //gameObject = heldItem;
/// Let animation control the rigidbody and ignore collisions
rigidbody.isKinematic = false;
rigidbody.detectCollisions = false;
/// Let the rigidbody take over control, detect collisions
rigidbody.isKinematic = false;
rigidbody.detectCollisions = false;
}
}
function OnMouseDown() { if(itemHeld == false) { var heldItem = GameObject.Find("S2L- First Person Controller/held_Item"); print("ciicked"+gameObject.name); gameObject.transform.position = heldItem.transform.position; //gameObject = heldItem;
/// Let animation control the rigidbody and ignore collisions
rigidbody.isKinematic = false;
rigidbody.detectCollisions = false;
/// Let the rigidbody take over control, detect collisions
rigidbody.isKinematic = false;
rigidbody.detectCollisions = false;
itemHeld = true;
//print(heldItem);
}
}
Answer by efge · Mar 24, 2010 at 07:55 PM
You could add a FixedJoint as a component (GameObject.AddComponent) to the clicked object and set the players or First Person Controllers rigid body as the connectedBody.
Answer by kezmacgov · Apr 06, 2010 at 10:57 AM
i parented it to the fps controller in the end saved having to update but now my object shrinks when i kneel down. thanks for repsonse though
Your answer
![](https://koobas.hobune.stream/wayback/20220612125711im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to move an object towords another using forces 0 Answers
Move Rigidbody Relative To Camera, quick Q (hopefuly) 1 Answer
Clunky Mouse Follow 1 Answer
How can I move a corresponding object. 2 Answers
Move object with collision 1 Answer