Hello,
I have an angle var and a turret. I would like the turret to look at that angle which is an input from the user.
GameObject :
I have a turret model which is rigged and capable of rotating. I have an angle in another script which is static and is used in another script attached to the turret. The angle is varied using a sidescroller GUI.
Code :
var lockPos =0;
function Update ()
{
transform.LookAt(Vector3(Projectile.angle,lockPos,lockPos), Vector3.right);
}
Code Explanation:
I am trying the turret to look at angle which is “Projectile.angle” along the x-axis. I have defined Vector3.right as it is the x-axis(world). Moreover I made an attempt to lock the rotation in the y and z axis by defining it at zero.
Problem:
The turret for some reason rotates to the Z axis and lifts it’s cannon hand upwards, with respect to the x axis. Beyond that I even tried to adjust the “angle” which had no effect on the angle of the cannon.
Request:
I humbly request for the shot on the problem on the code or the code I should change. I am just trying to create Projectile motion in a 2D plane(x-y plane) using the LookAt() function. Apart from this, (not a main concern) if you guys know any good turret/cannon models to import - please do let me know.
Thank YOU
125125