quit box collider?

Hi, i have a question. I have this script for take wooden boxes and move, but when they collide with another box or a wall, spin like crazy !! Is possible make the boxes transparent like Half Life, and quit the collider until press another time β€œq” ??

[sorry for my english, is very poor :frowning: ]

#pragma strict

private var pickObj: Transform = null;
private var hit: RaycastHit;
private var dist: float;
private var newPos: Vector3;

function Update(){
    if(Input.GetKeyDown("q") && pickObj!=null)
    {
       pickObj = null;
    }
    else if(Input.GetKeyDown("q") || pickObj!=null){ // if left button creates a ray from the mouse
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (!pickObj){ // if nothing picked yet...
            if (Physics.Raycast(ray, hit) && hit.transform.tag == "Pick"){
                // if it's a rigidbody, zero its physics velocity
                if (hit.rigidbody) hit.rigidbody.velocity = Vector3.zero;
                pickObj = hit.transform; // now there's an object picked
                // remember its distance from the camera
                dist = Vector3.Distance(pickObj.position, Camera.main.transform.position);
            }
        }
        else { // if object already picked...
            newPos = ray.GetPoint(dist); // transport the object
            pickObj.position = newPos;   // to the mouse position 
        }    
    }
}

Yes I suggest you do this.

  • when picking up the object set the collider to disabled

  • possibly set the rigidbody to isKinematic

  • reset after

     function Update(){
     if(Input.GetKeyDown("q") && pickObj!=null)
     {
        pickObj.collider.enabled = true;
        pickObj = null;
        
     }
     else if(Input.GetKeyDown("q") || pickObj!=null){ // if left button creates a ray from the mouse
         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (!pickObj){ // if nothing picked yet...
             if (Physics.Raycast(ray, hit) && hit.transform.tag == "Pick"){
                 // if it's a rigidbody, zero its physics velocity
                 if (hit.rigidbody) hit.rigidbody.velocity = Vector3.zero;
                 pickObj = hit.transform; // now there's an object picked
                 pickObj.collider.enabled = false;
                 // remember its distance from the camera
                 dist = Vector3.Distance(pickObj.position, Camera.main.transform.position);
             }
         }
         else { // if object already picked...
             newPos = ray.GetPoint(dist); // transport the object
             pickObj.position = newPos;   // to the mouse position 
         }    
     }
    

    }

thanks, but when drop the box, not have collider and falls towards the center of the earth :frowning:

if i add β€œpickObj.collider.enabled = true;” at the end, not working, any suggestion?

(ah, the kinematic no, because the boxes are left floating in the air)