I have a script that allows me to pick up objects when i click on it, but when i pick up the object, the box collider stops working and the object can move through walls and the floor until i drop it and the collision works again.
public class PickUp : MonoBehaviour
{
public Transform destination;
void OnMouseDown()
{
GetComponent().isKinematic = true;
GetComponent().detectCollisions = true;
this.transform.position = destination.position;
this.transform.parent = GameObject.Find(“Hand”).transform;
}
void OnMouseUp()
{
this.transform.parent = null;
GetComponent().isKinematic = false;
}
}
the script is attached to objects that can be picked up
Please use code tags. See the sticky posts in the scripting section if you’re not sure how to do that. It’s really hard to read code that’s not formatted correctly and you may end up getting incorrect advice because someone has misread your code.
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly
It the problem related to you manipulating the detectCollisions property only on mouse down?
Kinematic = true. I imagine.
I do a cube you can carry like in portal once, I had to keep its rigidbody non kinematic in order for it to not pass through objects when colliding.
so instead you want to be adding a handle, and a movement force, which keeps the cube at the handle if he stray. So if it does hit an object or wall it recenter itself towards handle position as best as possible
You see the key is that a kinematic rigidbody cannot exert force on your character( or anything ).