- Home /
 
               Question by 
               MetalsGames · Mar 09, 2015 at 09:17 AM · 
                cameraraycasttransformobjectmouseclick  
              
 
              Push object in direction of camera
Hello everyone, Im trying to get my First Person View Player to be able to walk up to a game object that is tagged "Nudge" or "Pushable" and that game object you click on should move in the direction you pushed it in. By the way, I have a ray cast that is shooting out from the center of the screen to pick up items and activate things. any help is much appreciated thanks in advanced.
here is my code.
 #pragma strict
 
 /*     NOTES
     
     Tags
     Movable = Item That can be picked up and movied around
     Nudge = Item that can be Nudge to create noise
     Pushable = Item that can be pushed greatly to knock over items
     PickUp = Item that can be picked up and placed in a hand or consumed
 */
 
 var PlayerCamera : GameObject;                   // The First Person Camera
 static public var Batteries : int; 
 static public var LeftHandObject : GameObject; // Object Currently in the Left Hand
 static public var RightHandObject : GameObject;// Object Currently in the Right Hand
 static public var LeftHandSOCKET : GameObject; // Left Hand SOCKET
 static public var RightHandSOCKET : GameObject;// Right Hand SOCKET
 var GrabDistantce : int;                        // The distants you must be in to grab item
 var LeftHandFull : boolean; 
 var RightHandFull : boolean;
 
 function Start ()
 {
     if(LeftHandSOCKET == null)
     {
         LeftHandSOCKET = GameObject.Find ("SOCKET_LeftHand");
     }
     if(RightHandSOCKET == null)
     {
         RightHandSOCKET = GameObject.Find ("SOCKET_RightHand");
     }
 }
 function Update () 
 {
     //Right Hand Grab Item
     if (Input.GetButtonDown("Fire2") && RightHandFull == false)
     {
         // Raycast for Right Hand Grab
         var RightHandcam : Transform = PlayerCamera.GetComponent.<Camera>().main.transform;
         var RightHandray = new Ray(RightHandcam.position, RightHandcam.forward);
         var RightHandhit : RaycastHit;
         
         if(Physics.Raycast (RightHandray, RightHandhit, GrabDistantce)) 
         {
             // RightHandObject = object you grabed
             RightHandObject = RightHandhit.collider.gameObject;
             
             if (RightHandhit.collider.gameObject.tag == "Movable")
             {
                 
                 PutItemInRightHand();
             }
             
             if (RightHandhit.collider.gameObject.tag == "Nudge")
             {
                 // This is where i need to put the code to activate the nudge force.
             }
             
             if (RightHandhit.collider.gameObject.tag == "Pushable")
             {
                 //Should be same as Nudge code just with more force.
             }
             
             
               Comment
              
 
               
              When posting a question, please phrase your desire in the form of a question. I have no idea what you're asking. Also, posting only the relevant code will improve your odds of getting help.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                