- Home /
Need Help, trying to make gun rotate around player, but it keeps snapping in the downward position
For some reason this code (im using a controller btw), keeps reverting the position of my gun downwards, but it does work in the way that it points the gun in the direction the joystick is facing, but once my finger is off the joystick, it snaps back to face downward
xAxis = Input.GetAxis("Mouse X");
yAxis = Input.GetAxis("Mouse Y");
float joystickAngle = Mathf.Atan2(xAxis , yAxis) * Mathf.Rad2Deg;
pivot.transform.rotation = Quaternion.Slerp(pivot.transform.rotation, Quaternion.Euler(pivot.transform.rotation.x, pivot.transform.rotation.y, joystickAngle - 90f),Time.deltaTime * 5 );
Answer by CaptainPickle77 · Jan 29, 2019 at 12:20 PM
The problem with that code is that my game is 3d from a sort of 2d perspective (like super smash bros) and I want the rotation of the gun to match the rotation of my controller right joystick.
Your answer
Follow this Question
Related Questions
Joystick for WASD & Joystick for Camera? 0 Answers
Rotating game object using UI Joystick 0 Answers
C# Clamp joystick rotation 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do you make a Main Menu that only takes Joystick input and is not affected by the Cursor 2 Answers