- Home /
 
picked up objects pass through wall
hi; i want to pick up objects.i find this code but with this code my object pass through wall and other object .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 {
         if(canPush){
         newPos = ray.GetPoint(dist);
         pickObj.rigidbody.MovePosition(newPos);
         
         }
        }    
     }
 
     else {
        pickObj = null;
     }
      
 }
 
 function OnCollisionEnter (col : Collision) {
 if(col.gameObject.tag == "wall") {
 
 canPush = true; } }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
In what way can I make a GUI Inventory? 0 Answers
Pick the oldest object from an array. 2 Answers
Storing items in inventory 1 Answer
picking object 1 Answer
FPS Equiping items? 0 Answers