I have a script that allows my player to pick up objects, if it meets a certain criteria:
public void Pickup(GameObject item) {
items = item.GetComponent<Renderer> ();
theitem = item;
ObjectSize = items.bounds.size.magnitude;
carried = true;
}
// Update is called once per frame
void Update () {
if (carried) {
newitempos = gameObject.transform.position + Camera.main.transform.forward * range;
theitem.transform.position = newitempos;
if (Input.GetKeyUp(KeyCode.Mouse1)) {
carried = false;
theitem.GetComponent<Rigidbody> ().velocity = Vector3.zero;
}
}
}
However, since the object’s motion is locked when it is being carried, it ends up going through other object’s colliders, that are too heavy to move, or aren’t allowed to move at all. I need a way to prevent this without causing too much work on the system.