- Home /
Question by
RedTwentyFour · Jul 15, 2014 at 09:27 PM ·
turretlocalrotation
LocalRotation problem in locked rotation.
So i want this turret to only rotate into a certain direction, and my code works out great, but only on world axis, if i rotate the turret itself itfails because it will always only lock up into the world axis direction, any idea how i can fix that? heres the script class:
void lockedRotation(Transform weaponTarget)
{
Vector3 relativePos = weaponTarget.position - weapon.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
if (rotation.x >= -0.7f && rotation.x <= 0 && rotation.y >= -0.7f && rotation.y <= 0.7f && rotation.z >= -0.7f && rotation.z <= 0.7f) {
weapon.rotation = Quaternion.Slerp( weapon.rotation, new Quaternion(
rotation.x,
rotation.y,
rotation.z,
rotation.w
), Time.deltaTime );
turretBase.rotation = Quaternion.Slerp( turretBase.rotation, new Quaternion(
0,
rotation.y,
0,
rotation.w
), Time.deltaTime );
}
Debug.DrawLine (weapon.position, weaponTarget.position, Color.red);
}
weapon.rotation is the rotation of the gun component of the turrt and turretBase is the base of it, including the pylons. i changed those 2 to localRotation it spins around forever...what am i am missing here?
RIck
Comment
Your answer
Follow this Question
Related Questions
Lock rotation of object 4 Answers
Turret bullet rotation problem 1 Answer
instantiate works on one but not other object 0 Answers
turret shoot if in range 1 Answer
Turret targeting is wrong 1 Answer