- Home /
How to rotate gameobject with mouse using new inputsystem
Hi everyone, I searched a whole lot on the web but I can't seem to find a full answer.
What is the best way to rotate a 3D gameobject with the mouse using the new input system?
I use the following action:
And I use the following code:
public void Look(InputAction.CallbackContext context){
Vector2 LineOfSight = context.ReadValue<Vector2>();
Debug.Log(LineOfSight);
if(LineOfSight.x != 0){mousePos.y = LineOfSight.x/(LineOfSight.x*-1);}
if(LineOfSight.y != 0){mousePos.x = LineOfSight.y/(LineOfSight.y*-1);}
Debug.Log(mousePos);
transform.Rotate(Vector3.up * mousePos.y);
}
What am I doing wrong, I can't find my mistake.
Thanks in advance for all your help!
Answer by eneIr · Jun 09, 2021 at 02:27 AM
Have you added the code to enable and disable the action map script in the void OnEnable() and OnDisable() functions?
I have not but when I play the game, I can see in the log that my code works, it just doesn't want to turn.
If that's the case, maybe you can change: transform.Rotate(Vector3.up * mousePos.y) to: transform.Rotate(Vector3.up, mousePos.y) I think that will work for you.
Your answer
Follow this Question
Related Questions
Multiple PlayerInputs fail to trigger actions 0 Answers
Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers
New Input System Multiple Actions from Single Button 0 Answers
How to get a key hold to do something which is stored in a variable as KeyCode ? 1 Answer
Trying to find what player inputed in Text Input field 1 Answer