Guest User

Untitled

a guest
Dec 19th, 2010
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //Point Bullets are insantiated at
  3. public var bulletPoint : GameObject;
  4.  
  5. //Main Camera Object
  6. public var cam : GameObject;
  7.  
  8. //Empty Object the bullet spawn point aims at
  9. public var aimer : Transform;
  10.  
  11. //The Farthest distance the aimer will function
  12. public var aimMaxDist : int = 100;
  13.  
  14. /////////////////////////
  15.  
  16. function Update ()
  17. {
  18.     //Create a variable to represent the Cameras Forward Direction
  19.     var fwd = cam.transform.TransformDirection(Vector3.forward);
  20.     //Create a variable to store the Raycasts Hit
  21.     var hit : RaycastHit;
  22.     //Variable to store the Racasts hit location
  23.     var hitPoint : Vector3;
  24.  
  25.     /*Create a Ray cast originating from the Cameras position, moving in the Cams forward direction
  26.     If the hit returns true we'll have the hitpoint location info, aimMaxDist is the length of the ray*/
  27.     Physics.Raycast(cam.transform.position, fwd, hit, aimMaxDist);
  28.     hitpoint = hit.point;
  29.  
  30.     //Tell the empty object to go to the hitpoint
  31.     aimer.transform.position = hitpoint;
  32.     //Make the object this script is attatched to look at the hitpoint empty
  33.     transform.LookAt(aimer);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment