- Home /
Top Down Shooter - Look at Cursor with Movement Compensation
Hey guys, I know there are a million posts on how to look at the cursor for TDS style games, but none of the solutions seem to be what I want. I should mention that I am new to Unity, but I am an experienced developer.
My setup is a TDS with perspective. I have the camera placed at the corner of the level and follows the player around. The camera is rotated 25 degrees about the X axis and 45 degrees about the y axis. This gives a look from the corner of the room towards the player and surrounding level. When pressing 'forward' the player moves in a north-east fashion relative to the camera (this is planned).
I need to add the aiming script now, where the player should be facing the cursor at all times.
All solutions that I have tried thus far do accomplish the look at the cursor part (well, sorta), but, are flawed in two ways.
A) They only work on 180 degrees of rotation, anything greater than that they reverse the players rotation.
B) The movement control does not compensate for the rotation, so instead of 'forward' still making the player move northeast relative to the camera, they run towards the cursor.
Ideally, I want the movement controls to keep the player moving in the same direction regardless of the players rotation. Any help would be greatly appreciated!
Answer by Loius · Oct 18, 2012 at 06:34 PM
Make the character's graphics a child object of "object 2". Only rotate the graphics object, and only move "object 2" - independent movement & rotation.
You can use transform.LookAt to have an object's Z axis face in a certain direction. It's probably worth using that on the player graphics - look at the cursor's position (being sure to zero the Y element of the direction so the player doesn't rotate 'vertically').
$$anonymous$$akes sense. I will give it a shot after work. Thanks for the reply
Your answer
Follow this Question
Related Questions
What is difference between local and global coord Vector3. 1 Answer
Having a plane at exactly the far clip of a camera 1 Answer
How to implement lock on with a camera that is not a child of the player object? 1 Answer
Move camera relative to current position 0 Answers
Prevent camera from rolling while looking at object 1 Answer