# LookAt rotation limit?

 0 Hi, I'm making a vehicular combat game, but I have a problem. When a car is in front of me, my guns follow him, but that's good. The problem is that I can't get them working with a limitation. when I look at the angle they turn and do a lookat if they ar within the limit, they are stuck till the lookat seconds ar over. ``````var Gun1:Transform; var Gun2:Transform; var minimumY:float=-45; var maximumY:float=45; var CountDown:float=2.5; var MaxCarDistance:float= 75; private var rotationY:float =0; private var originalRotation:Quaternion; private var beginTime:float; private var restSeconds:float=0; private var Car: RaycastHit; private var GunAngle1:float; private var GunAngle2:float; function Start () { originalRotation = transform.localRotation; beginTime = Time.deltaTime; } function Update () { GunAngle1 = Quaternion.Angle(originalRotation, Gun1.localRotation); GunAngle2 = Quaternion.Angle(originalRotation, Gun2.localRotation); var hit : RaycastHit; if (Physics.Raycast(this.transform.position, this.transform.forward,hit,MaxCarDistance)) { if(hit.collider.tag == "AICar") { Debug.Log("raak"); Car = hit; restSeconds = CountDown; } } if(restSeconds>0) { if(Car.collider.tag == "AICar") { Debug.DrawLine (transform.position, hit.point); if(GunAngle1 > minimumY && GunAngle1 minimumY && GunAngle2 < maximumY) Gun2.transform.LookAt(Car.transform); //transform.LookAt(hit.transform); restSeconds -=Time.deltaTime; } } if(restSeconds <=0) { Gun1.transform.localRotation = Quaternion.Slerp(Gun1.transform.localRotation, originalRotation, Time.deltaTime*8); Gun2.transform.localRotation = Quaternion.Slerp(Gun2.transform.localRotation, originalRotation, Time.deltaTime*8); } Debug.Log(restSeconds); } `````` Thanks in advance more ▼ asked Apr 14 '10 at 01:58 PM Deoxyz 94 ● 2 ● 3 ● 7 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

Be the first one to answer this question

By Email:

Topics:

x2168
x329
x287
x243
x134

asked: Apr 14 '10 at 01:58 PM

Seen: 1985 times

Last Updated: Apr 14 '10 at 01:58 PM