- Home /
Struggling to set a RayCast from a camera object
I am trying to create a raycast for my tank turret, the idea is that the i have set a camera gameObject named NPCCam as a child of my turret object, and from there, if the players tank is hit by the ray, the NPC tank will start moving towards it, with its turret following the direction of the players tank, however if not, the tank should randomly move around the map.
I have given this a go but keep getting hit my compiler errors, and have searched around for an answer but as yet not succeded, any help on this matter would be much appreciated, need to get my NPC tank up and running!
function Update() { Debug.DrawLine(target.position, myTransform.position, Color.yellow);
var hit : RaycastHit;
var cam : Transform = Camera.main.transform;
var ray : Ray(cam.position, cam.forward);
if(Physics.Raycast(cam.position, cam.forward, hit, 10)) {
//rotate to look at the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
//
// else { //
// RANDOMLY MOVE
// } }
Please post the errors... It helps the people who are trying to help you a lot.
Your answer