- Home /
Picking up object occasionally causes player to fly through air
Hey y'all,
I've been messing around with a game where the player needs to pick up items and set them down in certain spots. I've hit an issue where upon picking up an object, every once in a while (when I'm pretty much standing on top of the object) the player flies through the air as if the object is hitting/colliding with the player. I've been troubleshooting this by trying to turn off the rigidbody, collider, etc, but for some reason it still occurs. Below is the code. Excuse some of the messiness, a lot of the code is me turning various things off to see if it'll stop the object being picked up from sending my character soaring. Below is my code:
function PickUp(go:GameObject){
if(!isJointed){
isJointed = true;
go.GetComponent(ItemStats).SwapIsLifted();
go.rigidbody.useGravity = false;
go.rigidbody.velocity = Vector3(0,0,0);
go.rigidbody.freezeRotation = true;
go.collider.isTrigger = true;
go.transform.position = GameObject.FindGameObjectWithTag("LeftHand").transform.position;
go.transform.parent = GameObject.FindGameObjectWithTag("LeftHand").transform;
go.transform.LookAt(GameObject.FindGameObjectWithTag("LeftHand").transform);
}
else{
go.collider.isTrigger = false;
go.GetComponent(ItemStats).SwapIsLifted();
go.rigidbody.useGravity = true;
go.rigidbody.drag = 0;
go.transform.parent = null;
isJointed = false;
go.rigidbody.freezeRotation = false;
}
}
Thanks!
Your answer
Follow this Question
Related Questions
switching gun on screen with gun you pick up. 3 Answers
Mouse locked in center 1 Answer
How to pick a weapon of the ground 1 Answer
Creating a small delay for a Pick up/drop script. 1 Answer
Increasing speed for a few seconds 2 Answers