Implemented a long jump, a dive, the ability to bunny hop and a somewhat messy fix to the straight down drop issue from the implemented gravity as well as expanding the test area to more easily test quick movements
This commit is contained in:
@@ -1111,7 +1111,7 @@ Transform:
|
||||
m_GameObject: {fileID: 736244541}
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 100, y: 0.5, z: 100}
|
||||
m_LocalScale: {x: 250, y: 0.5, z: 250}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 833538478}
|
||||
m_RootOrder: 0
|
||||
@@ -1284,9 +1284,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 83127dd120c01de45954b99cc4d669a5, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
speed: 10
|
||||
maxSpeed: 25
|
||||
acceleration: 3
|
||||
acceleration: 0.5
|
||||
friction: 0.1
|
||||
jumpHeight: 20
|
||||
gravity: 5
|
||||
|
||||
@@ -22,6 +22,7 @@ public class PlayerController : MonoBehaviour
|
||||
public GameObject playerModel;
|
||||
|
||||
private bool wallRunning = false;
|
||||
private bool diving = false;
|
||||
private int jump = 0;
|
||||
private int wall = 0;
|
||||
private float maxSpeedStore;
|
||||
@@ -34,9 +35,12 @@ public class PlayerController : MonoBehaviour
|
||||
private float zVelocity = 0.0f;
|
||||
private Vector3 moveDirection;
|
||||
private Vector3 velocity;
|
||||
private Vector3 gravityVelocity;
|
||||
|
||||
float startTime = 0.0f;
|
||||
float oneSec = 1.0f;
|
||||
float halfSec = 0.5f;
|
||||
float quarterSec = 0.25f;
|
||||
|
||||
void Start()
|
||||
{
|
||||
@@ -67,19 +71,20 @@ public class PlayerController : MonoBehaviour
|
||||
moveDirection = new Vector3(Input.GetAxis("Horizontal"), moveDirection.y, Input.GetAxis("Vertical"));
|
||||
moveDirection = transform.TransformDirection(moveDirection);
|
||||
moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f);
|
||||
moveDirection.y = yStore;
|
||||
|
||||
if (jump >= 2)
|
||||
{
|
||||
if(maxSpeed > maxSpeedStore/1.75f)
|
||||
if(maxSpeed > maxSpeedStore/1.5f)
|
||||
{
|
||||
maxSpeed -= acceleration;
|
||||
}
|
||||
}
|
||||
|
||||
moveDirection.y = yStore;
|
||||
|
||||
if (characterController.isGrounded)
|
||||
{
|
||||
diving = false;
|
||||
wallRunning = false;
|
||||
jump = 0;
|
||||
moveDirection.y = 0.0f;
|
||||
|
||||
@@ -114,13 +119,18 @@ public class PlayerController : MonoBehaviour
|
||||
startTime = Time.time;
|
||||
}
|
||||
|
||||
if(startTime + oneSec >= Time.time)
|
||||
if(startTime + halfSec >= Time.time)
|
||||
{
|
||||
|
||||
if(maxSpeed < maxSpeedStore*2)
|
||||
{
|
||||
maxSpeed += acceleration*2;
|
||||
}
|
||||
|
||||
if(Input.GetButton("Jump") && startTime + quarterSec >= Time.time)
|
||||
{
|
||||
maxSpeed += 5;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -139,6 +149,25 @@ public class PlayerController : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
startTime = Time.time;
|
||||
|
||||
if(Input.GetKey(KeyCode.LeftControl))
|
||||
{
|
||||
|
||||
characterController.height /= 2;
|
||||
capsule.height /= 2;
|
||||
transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z);
|
||||
diving = true;
|
||||
|
||||
} else {
|
||||
|
||||
characterController.height = controllerHeight;
|
||||
capsule.height = capsuleHeight;
|
||||
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Input.GetButtonDown("Jump") && jump <= 1)
|
||||
@@ -189,7 +218,7 @@ public class PlayerController : MonoBehaviour
|
||||
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)
|
||||
{
|
||||
@@ -205,6 +234,20 @@ public class PlayerController : MonoBehaviour
|
||||
|
||||
velocity.y = moveDirection.y;
|
||||
|
||||
Debug.Log(moveDirection.y+"\n");
|
||||
|
||||
if(moveDirection.y <= -5 && Mathf.Abs(velocity.x) <= 1.5f && Mathf.Abs(velocity.z) <= 1.5f)
|
||||
{
|
||||
velocity.x = velocity.x * Mathf.Abs(moveDirection.y);
|
||||
velocity.z = velocity.z * Mathf.Abs(moveDirection.y);
|
||||
}
|
||||
|
||||
if(diving)
|
||||
{
|
||||
velocity.x *= 1.5f;
|
||||
velocity.z *= 1.5f;
|
||||
}
|
||||
|
||||
// Move the controller
|
||||
characterController.Move(velocity * Time.deltaTime);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user