I have a 2d side scroller setup and I’m trying to have an object (a spawn point for pew pew pew) rotate around the player but still track the mouses movement. I honestly don’t know where to start for this one as rotation stuff just doesn’t click well for me. Anyone have an idea to solve this?
Accidentally posted this in the wrong board earlier… whoops
OH! We had completely different ideas. Sorry if I worded incorrectly or something but I meant that the spawn points axis is the player but is always looking towards the mouse.
Give that to the canon. The last value (Camera.main.transform.position.z) is the distance from the camera to the player. If your players position.z is one 0, just use the exact code i posted.
Hmmm… While that does make the cannon actually respond to the mouse. It seems to stop following if the mouse is almost horizontal to the player. Then as the mouse moves further away from the player the canon continues to rotate to a different angle, no longer pointing at the mouse.
You can pass a second parameter to transform.LookAt which specifies the upward direction during the rotation. If you use the axis of rotation as the upward direction, you should find the gun tracks the mouse correctly.