Compare commits

..
3 changed files with 108 additions and 41 deletions
+10 -10
View File
@@ -167,7 +167,7 @@ GameObject:
- component: {fileID: 194035205}
m_Layer: 0
m_Name: Running Wall Left
m_TagString: Environment
m_TagString: Wall
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@@ -180,8 +180,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 194035203}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 62, y: 6.5, z: 12}
m_LocalScale: {x: 25, y: 20, z: 0.25}
m_LocalPosition: {x: 80, y: 6.5, z: 12}
m_LocalScale: {x: 75, y: 20, z: 0.25}
m_Children: []
m_Father: {fileID: 1013482115}
m_RootOrder: 0
@@ -366,7 +366,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 203887784}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 84, y: -0.5, z: 6}
m_LocalPosition: {x: 120, y: -0.5, z: 6}
m_LocalScale: {x: 20, y: 0.5, z: 12}
m_Children: []
m_Father: {fileID: 833538478}
@@ -1205,7 +1205,7 @@ CapsuleCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 741217452}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_IsTrigger: 1
m_Enabled: 1
m_Radius: 0.5
m_Height: 2
@@ -1391,7 +1391,7 @@ GameObject:
- component: {fileID: 858957127}
m_Layer: 0
m_Name: Running Wall Right
m_TagString: Environment
m_TagString: Wall
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
@@ -1404,8 +1404,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 858957125}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 62, y: 6.5, z: 0}
m_LocalScale: {x: 25, y: 20, z: 0.25}
m_LocalPosition: {x: 80, y: 6.5, z: 0}
m_LocalScale: {x: 75, y: 20, z: 0.25}
m_Children: []
m_Father: {fileID: 1013482115}
m_RootOrder: 1
@@ -2045,8 +2045,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1853948297}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 62, y: -3.5, z: 6}
m_LocalScale: {x: 25, y: 0.25, z: 12}
m_LocalPosition: {x: 80, y: -3.5, z: 6}
m_LocalScale: {x: 75, y: 0.25, z: 12}
m_Children: []
m_Father: {fileID: 833538478}
m_RootOrder: 1
+97 -31
View File
@@ -12,7 +12,6 @@ public class PlayerController : MonoBehaviour
CharacterController characterController;
CapsuleCollider capsule;
public float speed;
public float maxSpeed;
public float acceleration;
public float friction;
@@ -22,8 +21,12 @@ public class PlayerController : MonoBehaviour
public Transform pivot;
public GameObject playerModel;
private bool wallRunning = false;
private int jump = 0;
private int wall = 0;
private float maxSpeedStore;
private float maxSpeedCap = 100;
private float accelerationStore;
private float capsuleHeight;
private float controllerHeight;
private float transformHeight;
@@ -43,30 +46,34 @@ public class PlayerController : MonoBehaviour
controllerHeight = characterController.height;
capsuleHeight = capsule.height;
maxSpeedStore = maxSpeed;
accelerationStore = acceleration;
}
void OnControllerColliderHit(ControllerColliderHit hit)
{
if(hit.gameObject.tag == "Wall")
{
wallRunning = true;
wall++;
}
}
void Update()
{
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 = transform.TransformDirection(moveDirection);
moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f);
velocity.x += moveDirection.x * acceleration;
velocity.z += moveDirection.z * acceleration;
if (jump <= 1)
if (jump >= 2)
{
//moveDirection = moveDirection.normalized * speed; //Remove this line to make running diagonal the fastest standard run
maxSpeed = maxSpeedStore;
} else {
//moveDirection = (moveDirection.normalized * speed)/4; //Remove this line to make running diagonal the fastest standard run
maxSpeed = maxSpeedStore/2;
if(maxSpeed > maxSpeedStore/1.75f)
{
maxSpeed -= acceleration;
}
}
moveDirection.y = yStore;
@@ -76,13 +83,22 @@ public class PlayerController : MonoBehaviour
jump = 0;
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))
{
//moveDirection = (moveDirection.normalized * speed/2);
maxSpeed = maxSpeedStore/2;
} else {
//moveDirection = moveDirection.normalized * speed;
maxSpeed = maxSpeedStore;
if(maxSpeed > maxSpeedStore/2)
{
maxSpeed -= acceleration;
}
}
if(Input.GetKey(KeyCode.LeftControl))
@@ -101,40 +117,90 @@ public class PlayerController : MonoBehaviour
if(startTime + oneSec >= Time.time)
{
//moveDirection = (moveDirection.normalized * speed * 2);
maxSpeed = maxSpeedStore*2;
if(maxSpeed < maxSpeedStore*2)
{
maxSpeed += acceleration*2;
}
} else {
//moveDirection = (moveDirection.normalized * speed/4);
maxSpeed = maxSpeedStore/4;
if(maxSpeed > maxSpeedStore/4)
{
maxSpeed -= acceleration;
}
}
} else {
moveDirection = moveDirection.normalized * speed;
characterController.height = controllerHeight;
capsule.height = capsuleHeight;
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)
{
moveDirection.y = jumpHeight;
jump++;
}
if (characterController.collisionFlags == CollisionFlags.None)
{
wallRunning = false;
wall = 0;
}
moveDirection.y += Physics.gravity.y * gravity * Time.deltaTime;
if (wallRunning)
{
if(maxSpeed < maxSpeedStore*1.5f)
{
maxSpeed += acceleration;
}
jump = 0;
if(wall == 1)
{
startTime = Time.time;
}
if(startTime + oneSec < Time.time)
{
moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime;
} else {
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.y = moveDirection.y;
+1
View File
@@ -5,6 +5,7 @@ TagManager:
serializedVersion: 2
tags:
- Environment
- Wall
layers:
- Default
- TransparentFX