LookAt Problem

Hy Guys,

i have a Problem and dont know, how i fix it.
I have a Turret and a Target. The Target goes to Turret. The Turret is Rotating with Lookat to Target.
But my Turret is always 90 degrees further than it should be. Why?

The Turret is a Asset, i read, when Objects created in Blender or so, the facing is bad.
But when i create a Cube, same…
I rotate all objects to 90 degrees, Turret 90 degrees further than it should be.

I dont know…

Vector3 enemyPos = new Vector3(enemy.position.x, turret.transform.position.y, enemy.position.z);
turret.transform.LookAt (enemyPos);

Thanks for Help!!!

Greets Noxen

When you select your turret object, which color arrow points in the direction of the turret’s weapon?

Playmode:

Yes, that’s what I was guessing. The LookAt() method is intended to cause the +Z direction of an object to point in a certain direction.

One simple thing you can do is to insert an Empty object in the hierarchy. Turn the Empty with your script. Have the actual visual shape representing the turret be a child of the Empty, and turned so its red +X direction matches the Empty’s blue +Z direction. Now, when you turn the empty with LookAt(), the turret will turn as you expected.

Hierarchy:

EmptyTurretPivotPoint (rotate this Empty with LookAt())
TurretModel

The other approach is to correct this in the modeling program. Turn the mesh 90 degrees before you export it. Getting the correct rotation may take a little trial and error, with the various export options you have available.

1 Like

Oh my God, soooo simple xDDDD
Thank You!!!

If you wanna fix rotation while still in blender:

1 go to object mode
2 rotate -90 on the x
3 control+p apply rotation
4 profit

1 Like