I am making a game, where I want to have a character, a generic unity capsule, to be moved around using the arrow keys/WASD, and turned using the mouse. I made a script, which according to my knowledge, should work fine. Script:
public Rigidbody Player;
public float jumpheight;
public float Speed;
public bool isGrounded;
Vector3 jump;
void OnCollisionEnter(Collision col){
if (col.gameObject.tag == "Ground")
{
isGrounded = true;
Debug.Log ("IsGrounded = true");
}
else
{
isGrounded = false;
Debug.Log ("IsGrounded = false");
}
}
// Update is called once per frame
void FixedUpdate () {
float forward = Input.GetAxis ("Vertical");
float side = Input.GetAxis ("Horizontal");
float rotY = Input.GetAxis ("Mouse X");
gameObject.transform.Rotate (0, rotY, 0);
Vector3 speed = new Vector3(forward, 0.0f, side);
Player.AddForce(speed);
if (Input.GetButtonDown("Jump") && isGrounded == true)
{
Jump ();
}
}
void Jump(){
jump = new Vector3 (0.0f, jumpheight, 0.0f);
Player.AddForce(jump);
Debug.Log ("Jumping");
isGrounded = false;
}
However when I play the game, the character does not move, and even when it does, it does not follow the capsules’ “forward”. It just moves on the initial x and z axis.
Any help would be appreciated.