- Home /
Question by
JesseSomerville · Feb 17, 2014 at 03:24 PM ·
objectscalepickupwtf
Object changes shape randomly.
When I pick up an object it slightly changes size, and when I drop it, it greatly changes size. It's directional. It will expand about 1 unit away from the player and it will be slightly thinner. I have no clue whats happening.
#pragma strict
var Distance : float;
var MaxDistance : float = 4.0;
var Hand : GameObject;
var Item : GameObject;
var TheSystem : Transform;
var Weapon01 : GameObject;
var HoldingItem = false;
function Start () {
Hand = GameObject.Find("Hand");
Item = GameObject.Find("Cube");
Weapon01 = GameObject.Find("Weapon01");
}
function Update () {
var hit : RaycastHit;
if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (HoldingItem == false)
{
var ItemScale = Item.renderer.bounds.size;
}
if (Distance < MaxDistance && Input.GetMouseButtonDown(0) && HoldingItem == false && hit.collider.gameObject.tag == "PickUpable")
{
Destroy(Weapon01);
Item.rigidbody.useGravity = false;
Item.rigidbody.isKinematic = true;
Item = hit.collider.gameObject;
Item.transform.parent = Hand.transform;
Item.transform.position = Hand.transform.position;
HoldingItem = true;
var Wait = Time.time + 10;
}
}
if (HoldingItem && Input.GetMouseButtonDown(0) && Wait <= Time.time)
{
Item.transform.parent = null;
Item.rigidbody.useGravity = true;
Item.rigidbody.isKinematic = false;
HoldingItem = false;
}
if (HoldingItem)
{
Item.renderer.bounds.size = ItemScale;
print(ItemScale);
}
}
Comment
It was a problem with parenting and un-parenting the object.
You should post the answer to the problem that you were having so that others may use it for reference if they have a similar issue. That would be greatly appreciated by others I'm sure.
Best Answer
Answer by JesseSomerville · Feb 23, 2014 at 04:56 PM
The problem was A glitch with parenting and un-parenting the object. I fixed it by just having the object follow my hand object instead.