Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
996e1e3b20 | ||
|
|
386b51589e | ||
|
|
573b4815ea | ||
|
|
db8ae256a8 |
@@ -12,7 +12,6 @@ public class PlayerController : MonoBehaviour
|
|||||||
CharacterController characterController;
|
CharacterController characterController;
|
||||||
CapsuleCollider capsule;
|
CapsuleCollider capsule;
|
||||||
|
|
||||||
public float speed;
|
|
||||||
public float maxSpeed;
|
public float maxSpeed;
|
||||||
public float acceleration;
|
public float acceleration;
|
||||||
public float friction;
|
public float friction;
|
||||||
@@ -26,6 +25,8 @@ 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 maxSpeedCap = 100;
|
||||||
|
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)
|
||||||
@@ -62,24 +64,16 @@ public class PlayerController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
|
|
||||||
float yStore = moveDirection.y;
|
float yStore = moveDirection.y;
|
||||||
maxSpeed = maxSpeedStore;
|
|
||||||
//Need to switch to 'raw' when using keyboard
|
|
||||||
//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;
|
if (jump >= 2)
|
||||||
velocity.z += moveDirection.z * acceleration;
|
|
||||||
|
|
||||||
if (jump <= 1)
|
|
||||||
{
|
{
|
||||||
//moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run
|
if(maxSpeed > maxSpeedStore/1.75f)
|
||||||
//maxSpeed = maxSpeedStore;
|
{
|
||||||
|
maxSpeed -= acceleration;
|
||||||
} else {
|
}
|
||||||
//moveDirection = (moveDirection.normalized * speed)/4; //Remove this line to make running diagonal the fastest standard run
|
|
||||||
maxSpeed = maxSpeedStore/2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moveDirection.y = yStore;
|
moveDirection.y = yStore;
|
||||||
@@ -89,13 +83,22 @@ public class PlayerController : MonoBehaviour
|
|||||||
jump = 0;
|
jump = 0;
|
||||||
moveDirection.y = 0.0f;
|
moveDirection.y = 0.0f;
|
||||||
|
|
||||||
|
if(maxSpeed > maxSpeedStore)
|
||||||
|
{
|
||||||
|
maxSpeed -= acceleration/10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(maxSpeed < maxSpeedStore && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.LeftControl))
|
||||||
|
{
|
||||||
|
maxSpeed += acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
if(Input.GetKey(KeyCode.LeftShift))
|
if(Input.GetKey(KeyCode.LeftShift))
|
||||||
{
|
{
|
||||||
//moveDirection = (moveDirection.normalized * speed/2);
|
if(maxSpeed > maxSpeedStore/2)
|
||||||
maxSpeed = maxSpeedStore/2;
|
{
|
||||||
} else {
|
maxSpeed -= acceleration;
|
||||||
//moveDirection = moveDirection.normalized * speed;
|
}
|
||||||
maxSpeed = maxSpeedStore;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Input.GetKey(KeyCode.LeftControl))
|
if(Input.GetKey(KeyCode.LeftControl))
|
||||||
@@ -114,30 +117,28 @@ public class PlayerController : MonoBehaviour
|
|||||||
if(startTime + oneSec >= Time.time)
|
if(startTime + oneSec >= Time.time)
|
||||||
{
|
{
|
||||||
|
|
||||||
//moveDirection = (moveDirection.normalized * speed * 2);
|
if(maxSpeed < maxSpeedStore*2)
|
||||||
maxSpeed = maxSpeedStore*2;
|
{
|
||||||
|
maxSpeed += acceleration*2;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//moveDirection = (moveDirection.normalized * speed/4);
|
if(maxSpeed > maxSpeedStore/4)
|
||||||
maxSpeed = maxSpeedStore/4;
|
{
|
||||||
|
maxSpeed -= acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
moveDirection = moveDirection.normalized * speed;
|
|
||||||
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);
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
@@ -156,7 +157,12 @@ public class PlayerController : MonoBehaviour
|
|||||||
|
|
||||||
if (wallRunning)
|
if (wallRunning)
|
||||||
{
|
{
|
||||||
maxSpeed = maxSpeedStore*1.5f;
|
|
||||||
|
if(maxSpeed < maxSpeedStore*1.5f)
|
||||||
|
{
|
||||||
|
maxSpeed += acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
jump = 0;
|
jump = 0;
|
||||||
|
|
||||||
if(wall == 1)
|
if(wall == 1)
|
||||||
@@ -168,14 +174,33 @@ public class PlayerController : MonoBehaviour
|
|||||||
{
|
{
|
||||||
|
|
||||||
moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime;
|
moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime;
|
||||||
//wallRunning = false;
|
|
||||||
maxSpeed = maxSpeedStore;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
moveDirection.y = 0.0f;
|
moveDirection.y = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
velocity.x += moveDirection.x;
|
||||||
|
velocity.z += moveDirection.z;
|
||||||
|
|
||||||
|
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(maxSpeed > maxSpeedCap)
|
||||||
|
{
|
||||||
|
maxSpeed = maxSpeedCap;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(characterController.velocity == new Vector3(0, 0, 0))
|
||||||
|
{
|
||||||
|
maxSpeed = maxSpeedStore;
|
||||||
|
}
|
||||||
|
|
||||||
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
|
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
|
||||||
|
|
||||||
velocity.y = moveDirection.y;
|
velocity.y = moveDirection.y;
|
||||||
|
|||||||
Reference in New Issue
Block a user