Gun LookingAt target

I have a player object, a ‘target’ which is rotating around him and a gun which also rotates around the player but also looks at the target. Pretty much like here.

via GIPHY

I’m using the simple LookAt function (on my uzi object). Here’s what’s happening:

via GIPHY

No matter where I place my uzi, no matter how I rotate it, the result is the same. Perhaps I should use Quaternion.rotation, but it could cause some problems for me later on. Is there any way to make it work with LookAt? Thanks!

Evil_Weevil

Try something like this:

void Update () {

//Somehow get this position

Vector3 targetPos;

Vector3 myPos = transform.position;

this.transform.position = Quaternion.LookRotation (Vector3.forward, targetPos - myPos);

}

You might need to rotate your transform by another 90° depending on the situation but you will see when you get there. Also if this doesnt work for you, try changing the Vector3.forward to Vector3.up etc.

One of these should to the job.

Good Luck