2019-09-29 19:40:54 -04:00
|
|
|
using UnityEngine;
|
2020-01-11 14:04:14 -05:00
|
|
|
using UnityEngine.SceneManagement;
|
2019-09-29 19:40:54 -04:00
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
|
|
// This script moves the character controller forward
|
|
|
|
|
// and sideways based on the arrow keys.
|
|
|
|
|
// It also jumps when pressing space.
|
|
|
|
|
// Make sure to attach a character controller to the same game object.
|
|
|
|
|
// It is recommended that you make only one call to Move or SimpleMove per frame.
|
|
|
|
|
|
|
|
|
|
public class PlayerController : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
CharacterController characterController;
|
2019-12-05 22:42:16 -05:00
|
|
|
CapsuleCollider capsule;
|
2019-09-29 19:40:54 -04:00
|
|
|
|
2020-01-10 00:26:44 -05:00
|
|
|
public bool finished = false;
|
2020-01-11 14:04:14 -05:00
|
|
|
public bool respawn = false;
|
|
|
|
|
public int lives = 3;
|
2020-01-19 20:59:20 -05:00
|
|
|
public static int shownLives = 3;
|
2019-12-14 23:40:14 -05:00
|
|
|
public float maxSpeed;
|
|
|
|
|
public float acceleration;
|
|
|
|
|
public float friction;
|
2019-12-05 21:57:29 -05:00
|
|
|
public float jumpHeight;
|
2019-11-10 21:04:52 -05:00
|
|
|
public float gravity;
|
|
|
|
|
public float rotationSpeed;
|
|
|
|
|
public Transform pivot;
|
|
|
|
|
public GameObject playerModel;
|
2020-02-08 19:08:36 -05:00
|
|
|
public AudioSource jumpNoise;
|
2020-02-08 22:52:46 -05:00
|
|
|
public AudioSource respawnNoise;
|
2020-02-09 18:40:13 -05:00
|
|
|
public Material[] characterSkins;
|
|
|
|
|
public static int characterSelect = 0;
|
|
|
|
|
public GameObject playerSkin;
|
2019-09-29 19:40:54 -04:00
|
|
|
|
2019-12-31 18:17:35 -05:00
|
|
|
private bool wallRunning = false;
|
2020-01-05 01:45:45 -05:00
|
|
|
private bool diving = false;
|
2020-01-05 12:56:23 -05:00
|
|
|
private bool sliding = false;
|
2019-12-05 21:57:29 -05:00
|
|
|
private int jump = 0;
|
2019-12-31 18:17:35 -05:00
|
|
|
private int wall = 0;
|
2020-01-05 12:56:23 -05:00
|
|
|
private int dive = 0;
|
2019-12-14 23:49:23 -05:00
|
|
|
private float maxSpeedStore;
|
2020-01-04 15:02:05 -05:00
|
|
|
private float accelerationStore;
|
2019-12-05 22:42:16 -05:00
|
|
|
private float capsuleHeight;
|
|
|
|
|
private float controllerHeight;
|
|
|
|
|
private float transformHeight;
|
2019-12-14 23:40:14 -05:00
|
|
|
private float xVelocity = 0.0f;
|
|
|
|
|
private float zVelocity = 0.0f;
|
2019-09-29 19:40:54 -04:00
|
|
|
private Vector3 moveDirection;
|
2019-12-14 23:40:14 -05:00
|
|
|
private Vector3 velocity;
|
2020-01-05 01:45:45 -05:00
|
|
|
private Vector3 gravityVelocity;
|
2019-09-29 19:40:54 -04:00
|
|
|
|
2020-01-05 12:56:23 -05:00
|
|
|
float slideTime = 0.0f;
|
|
|
|
|
float wallRunTime = 0.0f;
|
2020-01-11 15:55:01 -05:00
|
|
|
public float respawnTime = 0.0f;
|
2019-12-05 23:17:24 -05:00
|
|
|
float oneSec = 1.0f;
|
2020-01-05 01:45:45 -05:00
|
|
|
float halfSec = 0.5f;
|
|
|
|
|
float quarterSec = 0.25f;
|
2020-01-11 13:35:50 -05:00
|
|
|
float tenthSec = 0.1f;
|
2020-02-09 18:40:13 -05:00
|
|
|
MeshRenderer mr;
|
2019-12-05 23:17:24 -05:00
|
|
|
|
2019-09-29 19:40:54 -04:00
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
characterController = GetComponent<CharacterController>();
|
2019-12-05 22:42:16 -05:00
|
|
|
capsule = GetComponent<CapsuleCollider>();
|
|
|
|
|
transformHeight = transform.localScale.y;
|
|
|
|
|
controllerHeight = characterController.height;
|
|
|
|
|
capsuleHeight = capsule.height;
|
2019-12-14 23:49:23 -05:00
|
|
|
maxSpeedStore = maxSpeed;
|
2020-01-04 15:02:05 -05:00
|
|
|
accelerationStore = acceleration;
|
2020-01-18 12:23:59 -05:00
|
|
|
|
2020-01-19 20:59:20 -05:00
|
|
|
shownLives = 3;
|
|
|
|
|
|
2020-01-26 23:03:41 -05:00
|
|
|
Cursor.visible = false;
|
2020-01-18 12:23:59 -05:00
|
|
|
Cursor.lockState = CursorLockMode.Locked;
|
2020-02-09 18:40:13 -05:00
|
|
|
|
|
|
|
|
mr = playerSkin.GetComponent<MeshRenderer>();
|
|
|
|
|
mr.material = characterSkins[characterSelect];
|
2020-02-10 20:38:24 -05:00
|
|
|
|
2020-02-10 21:01:51 -05:00
|
|
|
Application.targetFrameRate = 60;
|
2019-09-29 19:40:54 -04:00
|
|
|
}
|
|
|
|
|
|
2019-12-21 23:17:24 -05:00
|
|
|
void OnControllerColliderHit(ControllerColliderHit hit)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(hit.gameObject.tag == "Wall")
|
|
|
|
|
{
|
2019-12-31 18:17:35 -05:00
|
|
|
wallRunning = true;
|
|
|
|
|
wall++;
|
2019-12-21 23:17:24 -05:00
|
|
|
}
|
2020-01-10 00:26:44 -05:00
|
|
|
|
|
|
|
|
if(hit.gameObject.tag == "Finish")
|
|
|
|
|
{
|
2020-01-11 00:46:40 -05:00
|
|
|
|
2020-01-10 00:26:44 -05:00
|
|
|
velocity = new Vector3(0,0,0);
|
2020-01-11 13:35:50 -05:00
|
|
|
moveDirection = new Vector3(0,0,0);
|
2020-01-10 00:26:44 -05:00
|
|
|
maxSpeed = 0;
|
2020-01-11 00:46:40 -05:00
|
|
|
|
2020-01-11 13:35:50 -05:00
|
|
|
finished = true;
|
|
|
|
|
respawnTime = Time.time;
|
2020-02-08 22:52:46 -05:00
|
|
|
respawnNoise.Play();
|
2020-01-14 22:01:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(hit.gameObject.tag == "Waypoint")
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
finished = true;
|
|
|
|
|
respawnTime = Time.time;
|
2020-02-08 22:52:46 -05:00
|
|
|
respawnNoise.Play();
|
2020-01-14 22:01:39 -05:00
|
|
|
|
|
|
|
|
}
|
2020-01-11 15:55:01 -05:00
|
|
|
|
|
|
|
|
if(hit.gameObject.tag == "Obstacle Portal")
|
|
|
|
|
{
|
2020-02-08 23:17:27 -05:00
|
|
|
FloorLevel.gameOver = false;
|
|
|
|
|
WaypointRace.gameOver = false;
|
|
|
|
|
InfinityRunner.gameOver = false;
|
2020-01-11 15:55:01 -05:00
|
|
|
SceneManager.LoadScene("Floor Level", LoadSceneMode.Single);
|
|
|
|
|
respawnTime = Time.time;
|
2020-02-08 22:52:46 -05:00
|
|
|
respawnNoise.Play();
|
2020-02-08 23:17:27 -05:00
|
|
|
FloorLevel.gameOver = false;
|
|
|
|
|
WaypointRace.gameOver = false;
|
|
|
|
|
InfinityRunner.gameOver = false;
|
2020-01-11 15:55:01 -05:00
|
|
|
}
|
2020-01-14 22:01:39 -05:00
|
|
|
|
|
|
|
|
if(hit.gameObject.tag == "Waypoint Portal")
|
|
|
|
|
{
|
2020-02-08 23:17:27 -05:00
|
|
|
FloorLevel.gameOver = false;
|
|
|
|
|
WaypointRace.gameOver = false;
|
|
|
|
|
InfinityRunner.gameOver = false;
|
2020-01-14 22:01:39 -05:00
|
|
|
SceneManager.LoadScene("Waypoint Race", LoadSceneMode.Single);
|
|
|
|
|
respawnTime = Time.time;
|
2020-02-08 22:52:46 -05:00
|
|
|
respawnNoise.Play();
|
2020-02-08 23:17:27 -05:00
|
|
|
FloorLevel.gameOver = false;
|
|
|
|
|
WaypointRace.gameOver = false;
|
|
|
|
|
InfinityRunner.gameOver = false;
|
2020-01-14 22:01:39 -05:00
|
|
|
}
|
2020-01-29 22:59:06 -05:00
|
|
|
|
|
|
|
|
if(hit.gameObject.tag == "Infinite Portal")
|
|
|
|
|
{
|
2020-02-08 23:17:27 -05:00
|
|
|
FloorLevel.gameOver = false;
|
|
|
|
|
WaypointRace.gameOver = false;
|
|
|
|
|
InfinityRunner.gameOver = false;
|
2020-01-29 22:59:06 -05:00
|
|
|
SceneManager.LoadScene("Infinity Runner", LoadSceneMode.Single);
|
|
|
|
|
respawnTime = Time.time;
|
2020-02-08 22:52:46 -05:00
|
|
|
respawnNoise.Play();
|
2020-02-08 23:17:27 -05:00
|
|
|
FloorLevel.gameOver = false;
|
|
|
|
|
WaypointRace.gameOver = false;
|
|
|
|
|
InfinityRunner.gameOver = false;
|
2020-01-29 22:59:06 -05:00
|
|
|
}
|
2019-12-31 18:17:35 -05:00
|
|
|
|
2019-12-21 23:17:24 -05:00
|
|
|
}
|
|
|
|
|
|
2019-09-29 19:40:54 -04:00
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
float yStore = moveDirection.y;
|
2019-12-14 23:40:14 -05:00
|
|
|
moveDirection = new Vector3(Input.GetAxis("Horizontal"), moveDirection.y, Input.GetAxis("Vertical"));
|
|
|
|
|
moveDirection = transform.TransformDirection(moveDirection);
|
|
|
|
|
moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f);
|
2020-01-05 01:45:45 -05:00
|
|
|
moveDirection.y = yStore;
|
2019-09-29 19:40:54 -04:00
|
|
|
|
2020-02-10 20:38:24 -05:00
|
|
|
moveDirection.y += Physics.gravity.y * gravity * Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
if (jump >= 2)
|
|
|
|
|
{
|
|
|
|
|
if(maxSpeed > maxSpeedStore/1.5f)
|
|
|
|
|
{
|
|
|
|
|
maxSpeed -= acceleration;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (characterController.collisionFlags == CollisionFlags.None)
|
|
|
|
|
{
|
|
|
|
|
wallRunning = false;
|
|
|
|
|
wall = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wallRunning)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if(maxSpeed < maxSpeedStore*1.5f)
|
|
|
|
|
{
|
|
|
|
|
maxSpeed += acceleration;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jump = 0;
|
|
|
|
|
|
|
|
|
|
if(wall == 1)
|
|
|
|
|
{
|
|
|
|
|
wallRunTime = Time.time;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(wallRunTime + oneSec < Time.time)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
moveDirection.y += Physics.gravity.y * (gravity/8) * Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
moveDirection.y = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-11 14:04:14 -05:00
|
|
|
if(transform.position.y < -20.0f)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
respawn = true;
|
|
|
|
|
respawnTime = Time.time;
|
2020-01-19 20:59:20 -05:00
|
|
|
shownLives--;
|
2020-02-08 22:52:46 -05:00
|
|
|
respawnNoise.Play();
|
2020-01-11 14:04:14 -05:00
|
|
|
|
|
|
|
|
if (SceneManager.GetActiveScene().name == "Hub World")
|
|
|
|
|
{
|
|
|
|
|
transform.position = new Vector3(0, 2, 0);
|
|
|
|
|
transform.Rotate(0.0f, 0.0f, 0.0f, Space.Self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-29 19:40:54 -04:00
|
|
|
if (characterController.isGrounded)
|
|
|
|
|
{
|
2020-02-10 20:38:24 -05:00
|
|
|
|
2020-01-05 01:45:45 -05:00
|
|
|
diving = false;
|
2020-01-05 12:56:23 -05:00
|
|
|
dive = 0;
|
2019-12-05 21:57:29 -05:00
|
|
|
jump = 0;
|
2019-09-29 19:40:54 -04:00
|
|
|
moveDirection.y = 0.0f;
|
|
|
|
|
|
2020-01-04 16:15:15 -05:00
|
|
|
if(maxSpeed > maxSpeedStore)
|
|
|
|
|
{
|
2020-01-05 15:57:18 -05:00
|
|
|
maxSpeed -= acceleration/5;
|
2020-01-04 16:15:15 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-05 15:57:18 -05:00
|
|
|
if(maxSpeed < maxSpeedStore && !Input.GetButton("Walk") && !Input.GetButton("Crouch"))
|
2020-01-04 16:15:15 -05:00
|
|
|
{
|
|
|
|
|
maxSpeed += acceleration;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 15:57:18 -05:00
|
|
|
if(Input.GetButton("Walk"))
|
2019-09-30 21:15:20 -04:00
|
|
|
{
|
2020-01-04 15:52:45 -05:00
|
|
|
if(maxSpeed > maxSpeedStore/2)
|
|
|
|
|
{
|
|
|
|
|
maxSpeed -= acceleration;
|
|
|
|
|
}
|
2019-09-30 21:15:20 -04:00
|
|
|
}
|
|
|
|
|
|
2020-01-18 12:23:59 -05:00
|
|
|
if((Input.GetButton("Crouch") || Input.GetAxis("Crouch") == 1.0f) && !PauseMenu.GameIsPaused)
|
2019-12-05 22:42:16 -05:00
|
|
|
{
|
2019-12-06 22:34:57 -05:00
|
|
|
|
|
|
|
|
characterController.height /= 2;
|
|
|
|
|
capsule.height /= 2;
|
|
|
|
|
transform.localScale = new Vector3(transform.localScale.x, transformHeight/2, transform.localScale.z);
|
|
|
|
|
|
2020-01-12 18:26:38 -05:00
|
|
|
if(Input.GetButtonDown("Crouch") || Input.GetAxis("Crouch") == 1.0f)
|
2019-12-05 23:17:24 -05:00
|
|
|
{
|
2020-01-15 18:44:22 -05:00
|
|
|
if((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && !sliding)
|
2020-01-05 12:56:23 -05:00
|
|
|
{
|
|
|
|
|
slideTime = Time.time;
|
2020-01-15 18:44:22 -05:00
|
|
|
sliding = true;
|
|
|
|
|
}
|
2019-12-21 21:00:36 -05:00
|
|
|
}
|
2019-12-05 23:17:24 -05:00
|
|
|
|
2020-01-15 18:44:22 -05:00
|
|
|
if(slideTime + halfSec > Time.time)
|
2019-12-05 23:17:24 -05:00
|
|
|
{
|
2020-01-15 18:44:22 -05:00
|
|
|
|
2020-01-04 15:52:45 -05:00
|
|
|
if(maxSpeed < maxSpeedStore*2)
|
|
|
|
|
{
|
2020-02-10 20:38:24 -05:00
|
|
|
maxSpeed += acceleration*5;
|
2020-01-04 15:52:45 -05:00
|
|
|
}
|
2020-01-05 01:45:45 -05:00
|
|
|
|
2020-01-05 12:56:23 -05:00
|
|
|
if(Input.GetButton("Jump") && slideTime + quarterSec >= Time.time)
|
2020-01-05 01:45:45 -05:00
|
|
|
{
|
|
|
|
|
maxSpeed += 5;
|
|
|
|
|
}
|
2019-12-06 22:34:57 -05:00
|
|
|
|
2019-12-14 23:40:14 -05:00
|
|
|
} else {
|
2020-01-15 18:44:22 -05:00
|
|
|
|
2020-01-04 15:52:45 -05:00
|
|
|
if(maxSpeed > maxSpeedStore/4)
|
|
|
|
|
{
|
2020-01-15 18:44:22 -05:00
|
|
|
maxSpeed -= acceleration*2;
|
2020-01-04 15:52:45 -05:00
|
|
|
}
|
2019-12-14 23:40:14 -05:00
|
|
|
|
2019-12-05 23:17:24 -05:00
|
|
|
}
|
2019-12-06 22:34:57 -05:00
|
|
|
|
2019-12-05 22:42:16 -05:00
|
|
|
} else {
|
2020-01-04 15:52:45 -05:00
|
|
|
|
2019-12-05 22:42:16 -05:00
|
|
|
characterController.height = controllerHeight;
|
|
|
|
|
capsule.height = capsuleHeight;
|
|
|
|
|
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);
|
2020-02-10 20:38:24 -05:00
|
|
|
sliding = false;
|
|
|
|
|
|
2019-12-05 22:42:16 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-05 01:45:45 -05:00
|
|
|
} else {
|
2020-02-10 20:38:24 -05:00
|
|
|
|
2020-01-05 12:56:23 -05:00
|
|
|
slideTime = Time.time;
|
2020-02-10 20:38:24 -05:00
|
|
|
sliding = false;
|
2020-01-05 01:45:45 -05:00
|
|
|
|
2020-01-18 12:23:59 -05:00
|
|
|
if((Input.GetButton("Crouch") || Input.GetAxis("Crouch") == 1.0f) && !PauseMenu.GameIsPaused)
|
2020-01-05 01:45:45 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-05 12:56:23 -05:00
|
|
|
//Might want to change move direction value to make triggering this speed up effect easier/harder
|
2020-01-12 18:26:38 -05:00
|
|
|
if(diving && moveDirection.y > 0.75 && (Input.GetButtonDown("Crouch") || Input.GetAxis("Crouch") == 1.0f ))
|
2020-01-05 12:56:23 -05:00
|
|
|
{
|
|
|
|
|
dive++;
|
|
|
|
|
if(dive == 1){
|
|
|
|
|
maxSpeed += 10;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-21 21:00:36 -05:00
|
|
|
}
|
2019-12-14 23:40:14 -05:00
|
|
|
|
2019-12-05 21:57:29 -05:00
|
|
|
if (Input.GetButtonDown("Jump") && jump <= 1)
|
|
|
|
|
{
|
|
|
|
|
moveDirection.y = jumpHeight;
|
|
|
|
|
jump++;
|
2020-02-08 19:08:36 -05:00
|
|
|
jumpNoise.Play();
|
2019-09-29 19:40:54 -04:00
|
|
|
|
2020-02-10 20:38:24 -05:00
|
|
|
if(wallRunning) wallRunning = false;
|
2019-12-21 23:17:24 -05:00
|
|
|
|
2020-02-10 20:38:24 -05:00
|
|
|
}
|
2019-12-14 23:40:14 -05:00
|
|
|
|
2020-02-10 20:38:24 -05:00
|
|
|
if(Input.GetButtonDown("Character Swap"))
|
2019-12-31 18:17:35 -05:00
|
|
|
{
|
2020-02-10 20:38:24 -05:00
|
|
|
characterSelect = Random.Range(0, characterSkins.Length);
|
|
|
|
|
mr.material = characterSkins[characterSelect];
|
2020-01-04 15:02:05 -05:00
|
|
|
}
|
|
|
|
|
|
2020-01-12 18:26:38 -05:00
|
|
|
if((Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0) || (Input.GetButton("Stop") || Input.GetAxis("Stop") == 1.0f)){
|
2020-01-04 15:02:05 -05:00
|
|
|
|
2020-01-04 15:52:45 -05:00
|
|
|
//Remove or "lower" friction to add an 'ice' effect
|
2020-02-07 22:30:42 -05:00
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, 0.1f);
|
|
|
|
|
velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, 0.1f);
|
2020-02-01 18:28:22 -05:00
|
|
|
maxSpeed = 25;
|
2020-01-04 15:02:05 -05:00
|
|
|
|
2020-01-05 01:45:45 -05:00
|
|
|
}
|
2020-01-04 15:02:05 -05:00
|
|
|
|
2020-02-10 20:38:24 -05:00
|
|
|
//Debug.Log(transform.position);
|
|
|
|
|
Debug.Log(velocity.x + "," + velocity.z);
|
|
|
|
|
|
|
|
|
|
//Move the player in different directions based on camera look direction
|
|
|
|
|
if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
|
|
|
|
|
{
|
|
|
|
|
transform.rotation = Quaternion.Euler(0f, pivot.rotation.eulerAngles.y, 0f);
|
|
|
|
|
Quaternion newRotation = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
|
|
|
|
|
playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, newRotation, rotationSpeed * Time.deltaTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FixedUpdate()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
velocity.x += moveDirection.x;
|
|
|
|
|
velocity.z += moveDirection.z;
|
|
|
|
|
|
2020-02-07 22:30:42 -05:00
|
|
|
//Remove or "lower" friction to add an 'ice' effect
|
2020-02-10 20:38:24 -05:00
|
|
|
velocity.x = Mathf.SmoothDamp(velocity.x, 0.0f, ref xVelocity, friction);
|
|
|
|
|
velocity.z = Mathf.SmoothDamp(velocity.z, 0.0f, ref zVelocity, friction);
|
2020-02-07 22:30:42 -05:00
|
|
|
|
2020-01-04 15:52:45 -05:00
|
|
|
if(characterController.velocity == new Vector3(0, 0, 0))
|
|
|
|
|
{
|
|
|
|
|
maxSpeed = maxSpeedStore;
|
2020-01-04 15:02:05 -05:00
|
|
|
}
|
2019-12-31 18:17:35 -05:00
|
|
|
|
2019-12-14 23:40:14 -05:00
|
|
|
velocity = Vector3.ClampMagnitude(velocity, maxSpeed);
|
2019-09-29 19:40:54 -04:00
|
|
|
|
2019-12-21 21:00:36 -05:00
|
|
|
velocity.y = moveDirection.y;
|
|
|
|
|
|
2019-09-29 19:40:54 -04:00
|
|
|
// Move the controller
|
2020-01-11 14:04:14 -05:00
|
|
|
if((finished == false || respawn == false) && respawnTime + tenthSec < Time.time)
|
2020-01-11 13:35:50 -05:00
|
|
|
{
|
|
|
|
|
characterController.Move(velocity * Time.deltaTime);
|
2020-01-11 14:15:38 -05:00
|
|
|
respawn = false;
|
2020-01-11 13:35:50 -05:00
|
|
|
}
|
2020-02-10 20:38:24 -05:00
|
|
|
|
2019-09-29 19:40:54 -04:00
|
|
|
}
|
|
|
|
|
}
|