Got momentum based movement fully functional while fixing a few player controller bugs and preferential tweaks
This commit is contained in:
@@ -1286,7 +1286,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
speed: 10
|
speed: 10
|
||||||
maxSpeed: 25
|
maxSpeed: 25
|
||||||
acceleration: 5
|
acceleration: 3
|
||||||
friction: 0.1
|
friction: 0.1
|
||||||
jumpHeight: 20
|
jumpHeight: 20
|
||||||
gravity: 5
|
gravity: 5
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ 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/4;
|
maxSpeed = maxSpeedStore/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
moveDirection.y = yStore;
|
moveDirection.y = yStore;
|
||||||
@@ -92,7 +92,8 @@ public class PlayerController : MonoBehaviour
|
|||||||
capsule.height /= 2;
|
capsule.height /= 2;
|
||||||
transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z);
|
transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z);
|
||||||
|
|
||||||
if(Input.GetKeyDown(KeyCode.LeftControl) && characterController.velocity != new Vector3(0, 0, 0))
|
if(Input.GetKeyDown(KeyCode.LeftControl) && characterController.velocity != new Vector3(0, 0, 0)
|
||||||
|
&& (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0))
|
||||||
{
|
{
|
||||||
startTime = Time.time;
|
startTime = Time.time;
|
||||||
}
|
}
|
||||||
@@ -117,13 +118,12 @@ public class PlayerController : MonoBehaviour
|
|||||||
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
|
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, friction);
|
}
|
||||||
velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, friction);
|
|
||||||
|
|
||||||
} else {
|
if(Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0){
|
||||||
|
|
||||||
velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, friction*3);
|
velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, friction);
|
||||||
velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, friction*3);
|
velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, friction);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,15 +134,15 @@ public class PlayerController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
moveDirection.y += Physics.gravity.y * gravity * Time.deltaTime;
|
moveDirection.y += Physics.gravity.y * gravity * Time.deltaTime;
|
||||||
velocity.y = moveDirection.y;
|
|
||||||
|
|
||||||
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
|
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
|
||||||
|
|
||||||
|
velocity.y = moveDirection.y;
|
||||||
|
|
||||||
// Move the controller
|
// Move the controller
|
||||||
characterController.Move(velocity * Time.deltaTime);
|
characterController.Move(velocity * Time.deltaTime);
|
||||||
|
|
||||||
//Move the player in different directions based on camera look direction
|
//Move the player in different directions based on camera look direction
|
||||||
//Need to switch to 'raw' when using keyboard
|
|
||||||
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
||||||
{
|
{
|
||||||
transform.rotation = Quaternion.Euler(0f, pivot.rotation.eulerAngles.y, 0f);
|
transform.rotation = Quaternion.Euler(0f, pivot.rotation.eulerAngles.y, 0f);
|
||||||
|
|||||||
Reference in New Issue
Block a user