I’ve trying to create a script which acts as a player controller for a 3rd person type of game. I’ve had a multitude of problems which I can’t yet solve.
The first is that I’m not able to hold down such a button and the forward action is repeated. I’m only able to click once.
The second issue is that I don’t know how to change it to a local axis. This might not be the problem, but when a key is pressed, I want the character to go forward in the direction the character is facing, not along a global axis.
Finally, even though I have a float variable which i reference along all axis’s, I’m only able to move the character in 1 direction (along the z axis).
script
public class playercontroller : MonoBehaviour {
public float Speed = 7f;
public Rigidbody daRB;
// Use this for initialization
void Start () {
daRB = GetComponent< Rigidbody >();
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKeyDown("w"))
{
daRB.velocity = new Vector3(daRB.velocity.x, daRB.velocity.y, Speed);
}
if (Input.GetKeyDown("w") && Input.GetKeyDown("A"))
{
daRB.velocity = new Vector3(-Speed, daRB.velocity.y, Speed);
}
if (Input.GetButtonDown("w") && Input.GetButton("d"))
{
daRB.velocity = new Vector3(Speed, daRB.velocity.y, Speed);
}
if (Input.GetKeyDown("s"))
{
daRB.velocity = new Vector3(daRB.velocity.x, daRB.velocity.y, -Speed);
}
if (Input.GetButtonDown("s") && Input.GetButton("a"))
{
daRB.velocity = new Vector3(-Speed, daRB.velocity.y, -Speed);
}
if (Input.GetButtonDown("s") && Input.GetButton("d"))
{
daRB.velocity = new Vector3(Speed, daRB.velocity.y, -Speed);
}
}
}