Question by
Krullmizter · Nov 20, 2020 at 03:42 PM ·
rotationtransformeuleranglestransform.rotationaim
3D, Rotate gun towards mouse
Hi,
I'm creating a 3D third person shooter game. I have an aim function that gets called in the Update function whenever the user holds down the right mouse button. This is the code for the aim function:
void Aim() {
var aimX = Input.mousePosition.x;
var aimY = Input.mousePosition.y;
var aimZ = 0;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(aimX, aimY, aimZ), Time.fixedDeltaTime);
}
The issue I now have is that the rotation is the polar opposite of my mouse position every time I try to aim the gun towards the mouse position.
Comment
Your answer
Follow this Question
Related Questions
Rotating an object in script 0 Answers
Rotation problem 0 Answers
Rotating game object 1 Answer
How can I deal with eulers 1 Answer
My rotation is not the same in inspector as it is in the scirpt 0 Answers