Quantcast
Channel: Latest Questions by kezmacgov
Viewing all articles
Browse latest Browse all 10

move object to the hands of the user

$
0
0

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

Viewing all articles
Browse latest Browse all 10

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>