I need help resetting the rotation of the x-axis back to 0, while the rotation on the y-axis keeps going. It’s basically code for a turret enemy in my game. Here’s the piece:
void RotateMode()
{
transform.Rotate(new Vector3(0f, 100f, 0f) * Time.deltaTime);
}
Any help is appreciated.
You want to have separate float values for traverse and elevate and adjust those values only.
Check this post here, I did a whole writeup about it, including some sample code:
Hi, i am trying to aim turrets at a flying target and noticed during testing that they miss already at 12 units distance... They are consistently too low by like 1-2 degrees.
Is there something i can do about it?
I wrote my own method to calculate the angles because i need the two angles on seperate objects. Like, one is the base rotating on Y and the other one is the cannon rotating on Z.
I mean, this code works.. It just isn't precise enough
Vector3 xzPlaneDiff = turretBase.position - …
1 Like
arfish
April 24, 2020, 5:53pm
3
Have you tried eulerAngles? Like this:
transform.eulerAngles = new Vector3(0f, transform.eulerAngles.y, transform.eulerAngles.z);
1 Like
arfish:
Have you tried eulerAngles? Like this:
transform.eulerAngles = new Vector3(0f, transform.eulerAngles.y, transform.eulerAngles.z);
Yep. I just found out. Works like a charm.