- Home /
rotation problems turrent guns
hey guts i am havind problems for days now with the rotation of my turrent`s guns they dont rotate like i wanted the body rotates on y no problem follows me
but the guns do rotate on the correct axis Z but the problem is when i am at lets say a few units away from the turrent the guns rotate towards me when i get closer they do rotate with me getting closer but when i jump they dont rotate to my hight position

// This is the Rotation of my turrent`s body works fine!..Rotation Y.
Vector3 dir = target.position - transform.position;
Quaternion lookRotation = Quaternion.LookRotation(dir);
Vector3 rotation = Quaternion.Lerp(partToRotate.rotation, lookRotation, Time.deltaTime * rotationSpeed).eulerAngles;
partToRotate.rotation = Quaternion.Euler(0f, rotation.y, 0f);
// This is the rotation of my turrents Guns that are a child of the body Rotation Z..
Vector3 targetPosition = new Vector3(target.position.x, transform.position.z, target.transform.position.z);
partToRotategunarms.transform.LookAt(targetPosition);
Answer by arrowmaster1252 · Jan 21 at 12:10 AM
Vector3 targetPosition = new Vector3(target.position.x, transform.position.z, target.transform.position.z); should be Vector3 targetPosition = new Vector3(target.position.x, transform.position.y, target.transform.position.z);
the y value of the vector 3 is taking in a z value
@arrowmaster1252 Hi thanks for you response. but yeah i did that in the first place also no luck i tried everything from changing the x.y.z value`s to looking up google tried to find tutorials for a 2 axis turrent but no luck i did test it with only simple gameobject instead of my turrent it self to rule out that it is my model or my axis on the model. i was planning on modeling a hd version of a turrent becouse this is just a place holder for testing my script but i cant seem to fix it. i changed the axis on the model its self so they are correct and changed the value`s back to what you suggested and still the same having the same problem it does rotate on.. partToRotategunarms but like in the screen shot it is not folowing me when i jump do you have other suggestions.. thanks... Wesley
Your answer