- Home /
How to rotate character respect ScreenView
Hi ! I'm creating a new script for my Controller Character and i found a lot of problems trying to fixed the movements of my object relative the ScreenView.
What i'm trying to do, is a 3D game with only 4 ways to move: W:up, S:down, A:left, D:right
(for now seems pretty easy to do but...)
But what i want, is when i switched my main camera to another position, i want that the character move respecting the view of the screen view, without worried about the position of the camera:
In the 1 camera scenario: if i press "A" the character will turns 90º and will face to the Left (perfect) But in the 2camer scenaro: if i press "A" the character will turns 90º and will face to the top.
I dont know how to do that, no matters where is the player facing, if i press A i want that automatically it faces to the left on the Screen View.
I tryed with:
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime); (fail)
Quaternion.LookRotation (fail)
Camera.WorldToScreenPoint (fail)
and for the last choice i tryed:
if (Input.GetKeyDown(KeyCode.W)) { transform.LookAt(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, Screen.height, Camera.main.farClipPlane / 2))); }
The last seems to works but makes a little weird position, it isnt a real 90º or 180º turn left.
any advice or ways to get this?