Hello all,
I have created a player controller script like this:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Rigidbody rb;
public Animator anim;
public float jumpPower;
private bool grounded;
private float distToGround;
public float hits;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
}
void OnCollisionStay(Collision collisionInfo)
{
grounded = true;
}
void OnCollisionExit(Collision collisionInfo)
{
grounded = false;
}
// Update is called once per frame
void Update () {
float moveHorizontal = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
rb.velocity = new Vector3(moveHorizontal *speed, rb.velocity.y, moveZ*speed);
if(Input.GetKeyDown(KeyCode.Space) && grounded == true)
{
Jump();
}
}
void Jump()
{
rb.AddForce(Vector3.up * jumpPower);
// animation.Play("jump_pose");
}
void FixedUpdate()
{
//
}
}
This script, however, does not seem to be working. It usually ends up freezing the player where you cannot move the player at all with any keys. This is demonstrated here: https://embed.gyazo.com/768346efa3444041f574b65912f852c2.gif
It is also demonstrated here showing the movement before it: Screen capture - 1b516af1ae6b493297139a7ad9ca61f1 - Gyazo
Could you please advise me on how to fix this? I would appreciate any help.
Thanks,
8Development