Hello Unity Community.
I’m new to all of this and currently playing around with the roll-a-ball tutorial and I was wondering if there is a way to turn the camera and player around on the Y-axis using the A & D key?
Hello Unity Community.
I’m new to all of this and currently playing around with the roll-a-ball tutorial and I was wondering if there is a way to turn the camera and player around on the Y-axis using the A & D key?
https://unity3d.com/learn/tutorials/modules/beginner/scripting/get-axis?playlist=17117
https://unity3d.com/learn/tutorials/modules/beginner/scripting/get-button-and-get-key?playlist=17117
covers off the input side (a d are horizontal axis keys in the default input manager setup)
rather than update the position you will need to provide a rotation
https://unity3d.com/learn/tutorials/modules/intermediate/scripting/quaternions?playlist=17117
Thanks LeftyRighty. After reading those and playing around more this is my player movement script;
public class Movement_2b : MonoBehaviour
{
publicfloat moveSpeed = 10f;
publicfloat turnSpeed = 50f;
void Update()
{
if (Input.GetKey(KeyCode.UpArrow))
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.DownArrow))
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.LeftArrow))
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.RightArrow))
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.W))
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.S))
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.A))
transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
if (Input.GetKey(KeyCode.D))
transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
}
}
I am confused on the Quaternions. How do I add in script under Input.GetKey(KeyCode.A)/(KeyCode.D) to make the camera turn with the player as it would in a 3d game? Also, is there a better way to write the above script?
Anyone point me in the right direction?