- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
shay4545 · Aug 01, 2015 at 06:13 PM ·
movement3d modelsforward3rd person controller3rd person camera
How to make player move according to camera's rotation
I have a script that currently makes the player run the direction the camera is facing. I want to make it so that whenever I press a or d that the player will run to the left or right of the direction that the camera is facing. Also, I want to make it so when I press the s key that it will run back towards the camera. If you have ever played Assassin's Creed, that is the kind of movement I'm looking for. Here is the script I currently have:
if(Input.GetKey(KeyCode.W) && Input.GetMouseButton(1)){
if(anim.GetCurrentAnimatorStateInfo(0).IsName("Running")){
GetComponent<Rigidbody> ().velocity = Camera.main.transform.forward * Input.GetAxis ("Vertical") * 6f;
Vector3 rot = transform.eulerAngles;
rot.z = 0f;
rot.y = Camera.main.transform.eulerAngles.y;
transform.eulerAngles = rot;
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotate 3rd person camera around player 1 Answer
Camera collision while using accelerometer 1 Answer
Simple Character Movement 1 Answer
How do I Create a 3rd Person character in Unity? 1 Answer
Moving character....northwest...? 1 Answer