Rotation Offset

Hi

I have a simple game im playing around with. What I currently have is a fps controller which I have removed everything but the “mouse look” script, the main camera(player) is looking down a shooting range, on each side of that I am going to have a turret also point down the range.

What I want the turret(s) todo is to point relative to where the player is looking(FIG 1), I can make the turrets inherit the camera rotation but when I try to ajust that rotation based on the angle from the main camera i cant seem to get it to work. The turret just flips around on its axis and sticks no longer follwing any input(FIG 2).

Thanks

alt text

Try making a raycast out of your player’s view, then use LookAt in the turrets with the coordinates of the raycast hit point.

Do you want the turrets to LookAt the target? Or look in the same direction as the camera. Fig 2 is the latter, they all look down the range, straight down. If you want the turrets to look at the target, use transform.LookAt(target). If you want them to look a some point down range, you need to know how far down range that is.

var target : GameObject;

function Update () {

var fwd = transform.TransformDirection(Vector3.forward);

var hit : RaycastHit;

Debug.DrawRay(transform.position, fwd * 50, Color.green);

if(Physics.Raycast(transform.position, fwd, hit, 50)){

	target.transform.LookAt(hit.point);

	Debug.Log(hit.point);

}

}