- Home /
[New Input System] Player Rotation & Cursor Following Mouse,[New Input System] Player Rotation & Cursor Object Following Mouse
I am in need of assistance understanding how rotating the player towards the mouse works, regarding the new input system. My project is a 3D, top-down, orthographic shooter game. I am using Unity 2020.1.7f1 HDRP.
Right now, I am moving the player with WASD just fine using
Rigidbody.AddForce();
. I even expanded on it myself by applying a sprint and crouch multiplier to the amount of force based on key state.There are currently no issues with the movement that I can detect. However, rotating the player is proving to be very difficult for me. I have tried various methods such as
player.transform.LookAt()
, rotating theRigidbody.MoveRotation()
, and even just straight-up setting the rotation.Here is my entire script, for reference, GameHandler.cs. I left my comments in so that you can see what I've attempted, namely in the TurnPlayer() method.
As is, I have a cursor GameObject that follows the mouse somewhat across the X-Axis but does nothing on the Z-Axis (world space) which is assigned from the mouse's Y-Axis (screen space). My idea was to have the cursor object follow the mouse, and then simply rotate the player along the Y-Axis (left/right) towards the cursor.
My script is just attached to an empty GameObject and has all the appropriate things linked.
My end goal is to have WASD movement, player rotate towards cursor every frame update without de-syncing, and camera follow player w/ zoom in/out function. I already have a good CameraHandler script, just need to get the input from mouse scroll wheel to know when to zoom in/out.
Please don't hesitate to bother me for more information. I am very eager to figure this out. Not a big believer in copy-pasta code. I appreciate all the help I can get. Thank you.
Forgot to mention, I am tracking the Mouse's position using a Pass Through Vector2 linked to Delta (Mouse) in the input settings asset.
Forgot to mention, I am tracking the $$anonymous$$ouse's position using a Pass Through Vector2 linked to Delta ($$anonymous$$ouse) in the input settings asset.
Your answer
Follow this Question
Related Questions
How to set a limit for my player rotation ? 0 Answers
How to "spin" a ring, but not rotate it? 1 Answer
Rigidbody Turning 2 Answers
Player Movement & Blend Tree - Can anyone help with my script? 1 Answer