Lookat not looking properly

Hey Everyone,

Have a stupid issue and not 100% sure how to fix it.

I am using a clyinder as a stand in for my gun which will point at various position on the screen. The game is like a first person shooter but you don’t move around. You just shoot objects that appear on the screen. I want this cylinder"gun" to follow the mouse position.

I used the LookAt command and my cylinder is definately following the mouse but it seems to be using the objects local forward vector instead of the global forward vector causing the side of the cylinder to face the mouse and not the tip of the cylinder.

Is there a way for the lookat command to use global instead of local? If not is there another way to get this cylinder to follow the mouse properly?

Yes, LookAt uses the local forward vector. It wouldn’t make sense otherwise! Global vector changes constantly when you rotate the object, so how do you tell which direction should be forward?

The quickest and easiest solution is to create an empty object that points the correct direction, make the gun a child of that object, and then use all the ‘lookat’ code on the empty instead.