- Home /
 
pick object and pass through other object
i want to pick up object .but when i picked up my object pass through other object and walls .here is my code.what should i do?
pragma strict
 private var pickObj : Transform = null;
 private var hit : RaycastHit;
 private var dist : float;
 private var newPos : Vector3;
 private var  canPush: boolean=false;
 
 
 function Update () {
  
 
     if (Input.GetMouseButton (0)) {
 
        var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 
        if (!pickObj) {
 
          if (Physics.Raycast(ray, hit) && hit.transform.tag == "Pick") {
 
           if (hit.rigidbody) hit.rigidbody.velocity = Vector3.zero;
           pickObj = hit.transform;
           dist = Vector3.Distance (pickObj.position, Camera.main.transform.position);
          }
        }
 
        else {
         
         newPos = ray.GetPoint(dist);
         pickObj.rigidbody.MovePosition(newPos);
         
        }    
        if(canPush){ pickObj.rigidbody.MovePosition(newPos); }
     }
 
     else {
        pickObj = null;
     }
      
 }
 
 function OnCollisionEnter (col : Collision) {
 
 if(col.gameObject.tag == "wall") {
 
 canPush = true; } }
 
              
               Comment
              
 
               
              Answer by hvilela · Oct 17, 2012 at 08:40 PM
Disable the collider as soon as you pick it and re-enable when you release.
Answer by CaioRosisca · Oct 17, 2012 at 10:16 PM
As @Henrique Vilela said..you just need to deactivate the colliders.. pickObj.GetComponent(BoxCollider).enabled = false ..or something like that..
if its a box collider..or just type whatever the type is
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
Instantiating droppable items on destroy game object 1 Answer
read notes like amnesia/penumbra 1 Answer