Havent made any real progress, stopping and saving this now to work on other things

This commit is contained in:
Gregory Campbell
2020-01-04 15:02:05 -05:00
parent db8ae256a8
commit 573b4815ea
+41 -18
View File
@@ -26,6 +26,7 @@ public class PlayerController : MonoBehaviour
private int jump = 0; private int jump = 0;
private int wall = 0; private int wall = 0;
private float maxSpeedStore; private float maxSpeedStore;
private float accelerationStore;
private float capsuleHeight; private float capsuleHeight;
private float controllerHeight; private float controllerHeight;
private float transformHeight; private float transformHeight;
@@ -45,6 +46,7 @@ public class PlayerController : MonoBehaviour
controllerHeight = characterController.height; controllerHeight = characterController.height;
capsuleHeight = capsule.height; capsuleHeight = capsule.height;
maxSpeedStore = maxSpeed; maxSpeedStore = maxSpeed;
accelerationStore = acceleration;
} }
void OnControllerColliderHit(ControllerColliderHit hit) void OnControllerColliderHit(ControllerColliderHit hit)
@@ -63,15 +65,13 @@ public class PlayerController : MonoBehaviour
float yStore = moveDirection.y; float yStore = moveDirection.y;
maxSpeed = maxSpeedStore; maxSpeed = maxSpeedStore;
acceleration = accelerationStore;
//Need to switch to 'raw' when using keyboard //Need to switch to 'raw' when using keyboard
//moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal")); //moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
moveDirection = new Vector3(Input.GetAxis("Horizontal"), moveDirection.y, Input.GetAxis("Vertical")); moveDirection = new Vector3(Input.GetAxis("Horizontal"), moveDirection.y, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection); moveDirection = transform.TransformDirection(moveDirection);
moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f); moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f);
velocity.x += moveDirection.x * acceleration;
velocity.z += moveDirection.z * acceleration;
if (jump <= 1) if (jump <= 1)
{ {
//moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run //moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run
@@ -79,7 +79,8 @@ public class PlayerController : MonoBehaviour
} else { } else {
//moveDirection = (moveDirection.normalized * speed)/4; //Remove this line to make running diagonal the fastest standard run //moveDirection = (moveDirection.normalized * speed)/4; //Remove this line to make running diagonal the fastest standard run
maxSpeed = maxSpeedStore/2; //maxSpeed = maxSpeedStore/1.75f;
acceleration = acceleration/2;
} }
moveDirection.y = yStore; moveDirection.y = yStore;
@@ -92,10 +93,12 @@ public class PlayerController : MonoBehaviour
if(Input.GetKey(KeyCode.LeftShift)) if(Input.GetKey(KeyCode.LeftShift))
{ {
//moveDirection = (moveDirection.normalized * speed/2); //moveDirection = (moveDirection.normalized * speed/2);
maxSpeed = maxSpeedStore/2; //maxSpeed = maxSpeedStore/2;
acceleration = acceleration/2;
} else { } else {
//moveDirection = moveDirection.normalized * speed; //moveDirection = moveDirection.normalized * speed;
maxSpeed = maxSpeedStore; //maxSpeed = maxSpeedStore;
acceleration = accelerationStore;
} }
if(Input.GetKey(KeyCode.LeftControl)) if(Input.GetKey(KeyCode.LeftControl))
@@ -115,17 +118,20 @@ public class PlayerController : MonoBehaviour
{ {
//moveDirection = (moveDirection.normalized * speed * 2); //moveDirection = (moveDirection.normalized * speed * 2);
maxSpeed = maxSpeedStore*2; //maxSpeed = maxSpeedStore*2;
acceleration = acceleration*2;
} else { } else {
//moveDirection = (moveDirection.normalized * speed/4); //moveDirection = (moveDirection.normalized * speed/4);
maxSpeed = maxSpeedStore/4; //maxSpeed = maxSpeedStore/4;
acceleration = acceleration/4;
} }
} else { } else {
moveDirection = moveDirection.normalized * speed; //moveDirection = moveDirection.normalized * speed;
moveDirection = moveDirection.normalized;
characterController.height = controllerHeight; characterController.height = controllerHeight;
capsule.height = capsuleHeight; capsule.height = capsuleHeight;
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z); transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
@@ -133,13 +139,6 @@ public class PlayerController : MonoBehaviour
} }
if(Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0){
velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, friction);
velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, friction);
}
if (Input.GetButtonDown("Jump") && jump <= 1) if (Input.GetButtonDown("Jump") && jump <= 1)
{ {
moveDirection.y = jumpHeight; moveDirection.y = jumpHeight;
@@ -156,7 +155,8 @@ public class PlayerController : MonoBehaviour
if (wallRunning) if (wallRunning)
{ {
maxSpeed = maxSpeedStore*1.5f; //maxSpeed = maxSpeedStore*1.5f;
acceleration = acceleration*1.5f;
jump = 0; jump = 0;
if(wall == 1) if(wall == 1)
@@ -169,13 +169,36 @@ public class PlayerController : MonoBehaviour
moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime; moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime;
//wallRunning = false; //wallRunning = false;
maxSpeed = maxSpeedStore; //maxSpeed = maxSpeedStore;
} else { } else {
moveDirection.y = 0.0f; moveDirection.y = 0.0f;
} }
} }
velocity.x += moveDirection.x * acceleration;
velocity.z += moveDirection.z * acceleration;
//if(Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0){
//Remove or lower friction to add an 'ice' effect
//velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, friction);
//velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, friction);
//}
if(velocity.x > 0.0f){
velocity.x -= 0.5f;
} else if(velocity.x < 0.0f){
velocity.x += 0.5f;
}
if(velocity.z > 0.0f){
velocity.z -= 0.5f;
} else if(velocity.z < 0.0f){
velocity.z += 0.5f;
}
velocity = Vector3.ClampMagnitude(velocity, maxSpeed); velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
velocity.y = moveDirection.y; velocity.y = moveDirection.y;