Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Point Bullets are insantiated at
- public var bulletPoint : GameObject;
- //Main Camera Object
- public var cam : GameObject;
- //Empty Object the bullet spawn point aims at
- public var aimer : Transform;
- //The Farthest distance the aimer will function
- public var aimMaxDist : int = 100;
- /////////////////////////
- function Update ()
- {
- //Create a variable to represent the Cameras Forward Direction
- var fwd = cam.transform.TransformDirection(Vector3.forward);
- //Create a variable to store the Raycasts Hit
- var hit : RaycastHit;
- //Variable to store the Racasts hit location
- var hitPoint : Vector3;
- /*Create a Ray cast originating from the Cameras position, moving in the Cams forward direction
- If the hit returns true we'll have the hitpoint location info, aimMaxDist is the length of the ray*/
- Physics.Raycast(cam.transform.position, fwd, hit, aimMaxDist);
- hitpoint = hit.point;
- //Tell the empty object to go to the hitpoint
- aimer.transform.position = hitpoint;
- //Make the object this script is attatched to look at the hitpoint empty
- transform.LookAt(aimer);
- }
Advertisement
Add Comment
Please, Sign In to add comment