x


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);
    }
}
more ▼

asked Mar 24 '10 at 02:53 PM

kezmacgov gravatar image

kezmacgov
37 5 5 6

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Mar 24 '10 at 07:55 PM

efge gravatar image

efge
5.1k 5 14 38

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Apr 06 '10 at 10:57 AM

kezmacgov gravatar image

kezmacgov
37 5 5 6

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1090
x496
x38

asked: Mar 24 '10 at 02:53 PM

Seen: 1328 times

Last Updated: Mar 24 '10 at 06:02 PM