Replaced character controller with rigidbody and fixed all player controller script errors - player character can only spin in place

This commit is contained in:
Gregory Campbell
2019-12-01 18:28:18 -05:00
parent 6c112d7784
commit 706ad21ed1
2 changed files with 28 additions and 20 deletions
+10 -5
View File
@@ -9,7 +9,7 @@ using System.Collections;
public class PlayerController : MonoBehaviour
{
CharacterController characterController;
Rigidbody rb;
public float speed;
public float jumpSpeed;
@@ -19,14 +19,19 @@ public class PlayerController : MonoBehaviour
public GameObject playerModel;
private bool extraJump = true;
private float distToGround;
private Vector3 moveDirection;
void Start()
{
characterController = GetComponent<CharacterController>();
rb = GetComponent<Rigidbody>();
}
void Update()
bool IsGrounded(){
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1f);
}
void FixedUpdate()
{
float yStore = moveDirection.y;
@@ -43,7 +48,7 @@ public class PlayerController : MonoBehaviour
moveDirection.y = yStore;
if (characterController.isGrounded)
if (IsGrounded())
{
extraJump = true;
moveDirection.y = 0.0f;
@@ -72,7 +77,7 @@ public class PlayerController : MonoBehaviour
moveDirection.y = moveDirection.y + (Physics.gravity.y * gravity * Time.deltaTime);
// Move the controller
characterController.Move(moveDirection * Time.deltaTime);
rb.AddForce(moveDirection * Time.deltaTime);
//Move the player in different directions based on camera look direction
//Need to switch to 'raw' when using keyboard