2022-10-30 23:59:35 +08:00
|
|
|
|
using SHADE;
|
|
|
|
|
using System;
|
2023-03-10 17:21:49 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using SHADE_Scripting.Audio;
|
2022-11-04 17:31:53 +08:00
|
|
|
|
using static Item;
|
2022-10-30 23:59:35 +08:00
|
|
|
|
|
|
|
|
|
public class PlayerController : Script
|
|
|
|
|
{
|
2022-10-31 16:45:47 +08:00
|
|
|
|
public enum RaccoonStates
|
|
|
|
|
{
|
2022-11-11 14:17:47 +08:00
|
|
|
|
IDLE,
|
2022-10-31 16:45:47 +08:00
|
|
|
|
WALKING,
|
|
|
|
|
RUNNING,
|
2022-11-01 23:28:31 +08:00
|
|
|
|
JUMP,
|
2022-10-31 16:45:47 +08:00
|
|
|
|
FALLING,
|
2022-11-10 13:06:37 +08:00
|
|
|
|
LANDED,
|
2022-10-31 16:45:47 +08:00
|
|
|
|
CAUGHT,
|
|
|
|
|
TOTAL
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-05 17:44:34 +08:00
|
|
|
|
public RigidBody rb { get; set; }
|
2022-11-24 14:05:02 +08:00
|
|
|
|
public Transform tranform { get; set; }
|
2022-11-25 14:45:19 +08:00
|
|
|
|
public Camera cam { get; set; }
|
2022-11-21 00:12:09 +08:00
|
|
|
|
public CameraArm camArm { get; set; }
|
2022-11-04 17:31:53 +08:00
|
|
|
|
private PickAndThrow pat;
|
2023-03-03 00:40:16 +08:00
|
|
|
|
public StateMachine stateMachine { get; set; }
|
2023-03-23 00:38:25 +08:00
|
|
|
|
public ParticleEmitter Leftsmoke { get; set; }
|
|
|
|
|
public ParticleEmitter Rightsmoke { get; set; }
|
2023-03-23 16:49:41 +08:00
|
|
|
|
public int smokeCount = 4;
|
2022-11-11 14:17:47 +08:00
|
|
|
|
|
2022-11-02 17:31:57 +08:00
|
|
|
|
public bool holdItem { get; set; }
|
2022-11-21 00:12:09 +08:00
|
|
|
|
public bool isAiming { get; set; }
|
2022-11-14 19:05:48 +08:00
|
|
|
|
|
2022-11-23 19:11:41 +08:00
|
|
|
|
[Tooltip("The game object for where the player will respawn to")]
|
2022-11-23 16:57:32 +08:00
|
|
|
|
public GameObject respawnPoint;
|
|
|
|
|
private float delayTimer = 0.0f;
|
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
[Tooltip("The current state fo the raccoon")]
|
2023-03-10 16:26:52 +08:00
|
|
|
|
public RaccoonStates currentState;
|
2022-10-31 16:45:47 +08:00
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
//Movement variables============================================================
|
|
|
|
|
[Tooltip("Max vel for walking")]
|
2023-03-16 17:14:57 +08:00
|
|
|
|
public float walkMaxMoveVel = 3.0f;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
[Tooltip("how much force is apply for walking")]
|
2022-11-23 20:48:40 +08:00
|
|
|
|
public float moveForce = 50.0f;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
[Tooltip("increase the moveForce and maxMoveVel by its amt")]
|
2022-11-23 20:48:40 +08:00
|
|
|
|
public float sprintMultiplier = 1.5f;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
|
2022-11-01 13:24:14 +08:00
|
|
|
|
private float oldForce;
|
|
|
|
|
private float maxOldVel;
|
|
|
|
|
private bool sprintIncreaseOnce = false;
|
2022-11-03 01:50:02 +08:00
|
|
|
|
|
|
|
|
|
public Vector2 axisMove { get; set; }
|
2022-11-02 17:31:57 +08:00
|
|
|
|
|
|
|
|
|
public bool isMoveKeyPress { get; set; }
|
2022-10-31 16:45:47 +08:00
|
|
|
|
|
2022-11-21 00:12:09 +08:00
|
|
|
|
[Tooltip("How fast player will turn")]
|
2022-11-23 20:48:40 +08:00
|
|
|
|
public float rotationFactorPerFrame = 5.0f;
|
2022-11-01 17:49:01 +08:00
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
//Jumping vars==================================================================
|
|
|
|
|
[Tooltip("max height of the jump")]
|
2022-11-23 20:48:40 +08:00
|
|
|
|
public float maxJumpHeight = 1.0f;
|
2023-02-18 22:21:23 +08:00
|
|
|
|
[Tooltip("max amount of time it will take for the jump")]
|
2022-11-23 20:48:40 +08:00
|
|
|
|
public float maxJumpTime = 0.5f;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
[Tooltip("increase gravity when falling")]
|
2022-11-23 20:48:40 +08:00
|
|
|
|
public float fallMultipler = 3.0f;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
private float initialJumpVel;
|
|
|
|
|
private bool isGrounded = true;
|
2022-11-01 17:49:01 +08:00
|
|
|
|
private float gravity = -9.8f;
|
|
|
|
|
private float groundGravity = -0.5f;
|
2023-02-18 22:21:23 +08:00
|
|
|
|
public bool landedOnJumpPad { get; set; }
|
|
|
|
|
[Tooltip("multiply height on Jump Pad ")]
|
|
|
|
|
public float jumpPadMultiplayer = 2.0f;
|
2022-10-30 23:59:35 +08:00
|
|
|
|
|
2023-03-16 17:14:57 +08:00
|
|
|
|
private bool jumpPadDrop = false;
|
|
|
|
|
private float dropTimer = 0.0f;
|
|
|
|
|
public float dropDuration = 0.5f;
|
|
|
|
|
public float jumpPadFallMultipler = 0.75f;
|
|
|
|
|
public float jumpPadMaxMoveVel = 1.0f;
|
|
|
|
|
private float currMoveVel = 0.0f;
|
|
|
|
|
|
2022-11-04 17:31:53 +08:00
|
|
|
|
//ItemMultipler==================================================================
|
2022-11-21 00:12:09 +08:00
|
|
|
|
[Tooltip("How light item will affect player jump")]
|
2022-11-04 17:31:53 +08:00
|
|
|
|
public float lightMultiper = 0.75f;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
[Tooltip("How medium item will affect player jump")]
|
2022-11-04 17:31:53 +08:00
|
|
|
|
public float mediumMultiper = 0.5f;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
[Tooltip("How heavy item will affect player jump")]
|
2022-11-04 17:31:53 +08:00
|
|
|
|
public float heavyMultiper = 0.25f;
|
|
|
|
|
|
2023-03-01 00:51:57 +08:00
|
|
|
|
//silhouette=====================================================================
|
|
|
|
|
public GameObject silhouettePlayer;
|
2023-03-03 00:40:16 +08:00
|
|
|
|
private Renderable silhouettePlayerRend;
|
2023-03-01 00:51:57 +08:00
|
|
|
|
public GameObject silhouetteBag;
|
2023-03-03 00:40:16 +08:00
|
|
|
|
private Renderable silhouetteBagRend;
|
2023-03-01 00:51:57 +08:00
|
|
|
|
|
2023-03-14 17:18:52 +08:00
|
|
|
|
public bool playLandedAnimation { get; set; }
|
|
|
|
|
|
2023-03-23 00:38:25 +08:00
|
|
|
|
|
|
|
|
|
public GameObject leftParticle;
|
|
|
|
|
public GameObject rightParticle;
|
|
|
|
|
|
2022-10-30 23:59:35 +08:00
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
2022-11-04 17:31:53 +08:00
|
|
|
|
//default setup
|
2022-11-02 17:31:57 +08:00
|
|
|
|
isMoveKeyPress = false;
|
|
|
|
|
holdItem = false;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
isAiming = false;
|
2023-02-18 22:21:23 +08:00
|
|
|
|
landedOnJumpPad = false;
|
2022-11-04 17:31:53 +08:00
|
|
|
|
|
|
|
|
|
//Jump setup
|
|
|
|
|
float timeToApex = maxJumpTime / 2;
|
|
|
|
|
gravity = (-2 * maxJumpHeight) / MathF.Pow(timeToApex, 2);
|
|
|
|
|
initialJumpVel = (2 * maxJumpHeight) / timeToApex;
|
|
|
|
|
|
2022-11-01 17:49:01 +08:00
|
|
|
|
//rigidbody check
|
2022-10-30 23:59:35 +08:00
|
|
|
|
rb = GetComponent<RigidBody>();
|
2022-11-22 17:28:48 +08:00
|
|
|
|
if (!rb)
|
2023-03-10 00:16:38 +08:00
|
|
|
|
Debug.LogError("RigidBody is MISSING!");
|
2022-11-01 01:31:13 +08:00
|
|
|
|
|
2022-11-01 17:49:01 +08:00
|
|
|
|
//Transform check
|
2022-11-01 01:31:13 +08:00
|
|
|
|
tranform = GetComponent<Transform>();
|
2022-11-22 17:28:48 +08:00
|
|
|
|
if(!tranform)
|
2023-03-10 00:16:38 +08:00
|
|
|
|
Debug.LogError("tranform is MISSING!");
|
|
|
|
|
|
2022-11-14 19:05:48 +08:00
|
|
|
|
stateMachine = AddScript<StateMachine>();
|
2022-11-13 21:56:28 +08:00
|
|
|
|
Dictionary<Type, BaseState> dictionary = new Dictionary<Type, BaseState>();
|
2023-03-14 17:18:52 +08:00
|
|
|
|
dictionary.Add(typeof(PlayerIdleState), new PlayerIdleState(stateMachine));
|
|
|
|
|
dictionary.Add(typeof(PlayerWalkState), new PlayerWalkState(stateMachine));
|
2023-03-10 16:26:52 +08:00
|
|
|
|
dictionary.Add(typeof(PlayerRunState), new PlayerRunState(stateMachine));
|
2022-11-20 16:27:39 +08:00
|
|
|
|
dictionary.Add(typeof(PlayerJumpState), new PlayerJumpState(stateMachine));
|
|
|
|
|
dictionary.Add(typeof(PlayerFallState), new PlayerFallState(stateMachine));
|
|
|
|
|
dictionary.Add(typeof(PlayerLandState), new PlayerLandState(stateMachine));
|
|
|
|
|
dictionary.Add(typeof(PlayerCaughtState), new PlayerCaughtState(stateMachine));
|
2022-11-14 19:05:48 +08:00
|
|
|
|
stateMachine.InitStateMachine(dictionary);
|
2022-11-13 21:56:28 +08:00
|
|
|
|
|
2023-03-01 00:51:57 +08:00
|
|
|
|
if (!silhouettePlayer)
|
|
|
|
|
Debug.LogError("silhouettePlayer EMPTY");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
silhouettePlayerRend = silhouettePlayer.GetComponent<Renderable>();
|
|
|
|
|
silhouettePlayerRend.Material.SetProperty<float>("data.offset", 0.1f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!silhouetteBag)
|
|
|
|
|
Debug.LogError("silhouetteBag EMPTY");
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
silhouetteBagRend = silhouetteBag.GetComponent<Renderable>();
|
|
|
|
|
silhouetteBagRend.Material.SetProperty<float>("data.offset", 0.1f);
|
|
|
|
|
}
|
2023-03-10 17:21:49 +08:00
|
|
|
|
|
|
|
|
|
AudioHandler.audioClipHandlers["footsteps"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_footsteps");
|
2023-03-25 02:38:56 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["Jump"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_jump");
|
|
|
|
|
AudioHandler.audioClipHandlers["JumpPad"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_jumpPad");
|
|
|
|
|
AudioHandler.audioClipHandlers["Land"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_land");
|
|
|
|
|
AudioHandler.audioClipHandlers["RaccoonCaught"] = Audio.CreateAudioClip("event:/Raccoon/raccoon_caught");
|
2023-03-14 17:18:52 +08:00
|
|
|
|
|
|
|
|
|
playLandedAnimation = false;
|
2023-03-22 21:31:40 +08:00
|
|
|
|
|
2023-03-23 00:38:25 +08:00
|
|
|
|
Leftsmoke = leftParticle.GetComponent<ParticleEmitter>();
|
|
|
|
|
if (!Leftsmoke)
|
|
|
|
|
Debug.LogError("left ParticleEmitter MISSING");
|
|
|
|
|
Rightsmoke = rightParticle.GetComponent<ParticleEmitter>();
|
|
|
|
|
if (!Leftsmoke)
|
|
|
|
|
Debug.LogError("right ParticleEmitter MISSING");
|
2022-10-30 23:59:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-10 16:26:52 +08:00
|
|
|
|
protected override void start()
|
|
|
|
|
{
|
|
|
|
|
currentState = RaccoonStates.IDLE;
|
|
|
|
|
stateMachine.SetState(typeof(PlayerIdleState));
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 16:57:32 +08:00
|
|
|
|
protected override void lateUpdate()
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-02-21 19:31:50 +08:00
|
|
|
|
|
2022-10-30 23:59:35 +08:00
|
|
|
|
protected override void update()
|
|
|
|
|
{
|
2023-03-02 17:33:02 +08:00
|
|
|
|
if (GameManager.Instance.GamePause || !GameManager.Instance.stealFoodPopUpDone)
|
2023-02-21 19:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-01 00:51:57 +08:00
|
|
|
|
if (silhouettePlayerRend && silhouetteBagRend)
|
2022-11-23 16:57:32 +08:00
|
|
|
|
{
|
2023-03-01 00:51:57 +08:00
|
|
|
|
Vector3 dis = Camera.GetMainCamera().Position - GameObject.GetComponent<Transform>().LocalPosition;
|
|
|
|
|
float disSqr = dis.GetSqrMagnitude();
|
|
|
|
|
float ratio = System.Math.Clamp(1 - (disSqr / (1 + disSqr)), 0, 1.0f);
|
|
|
|
|
float temp = (1 - ratio) * 0.00075f;
|
|
|
|
|
if (temp <= 0.0006f)
|
|
|
|
|
temp = 0.1f;
|
|
|
|
|
silhouettePlayerRend.Material.SetProperty<float>("data.offset", temp);
|
|
|
|
|
silhouetteBagRend.Material.SetProperty<float>("data.offset", temp);
|
2022-11-23 16:57:32 +08:00
|
|
|
|
}
|
2023-03-01 00:51:57 +08:00
|
|
|
|
|
2022-11-22 17:28:48 +08:00
|
|
|
|
//PickAndThrow check
|
|
|
|
|
if (!pat)
|
|
|
|
|
{
|
|
|
|
|
pat = GetScript<PickAndThrow>();
|
|
|
|
|
if(!pat)
|
|
|
|
|
Debug.LogError("PickAndThrow is NULL!");
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-21 00:12:09 +08:00
|
|
|
|
if (!cam)
|
2023-03-01 01:16:34 +08:00
|
|
|
|
{
|
2022-11-02 17:31:57 +08:00
|
|
|
|
cam = GetComponentInChildren<Camera>();
|
2023-03-08 17:00:43 +08:00
|
|
|
|
if (pat)
|
2023-03-15 19:39:12 +08:00
|
|
|
|
{
|
2023-03-08 17:00:43 +08:00
|
|
|
|
cam.FOV = Settings.cameraFOV;
|
2023-03-15 19:39:12 +08:00
|
|
|
|
}
|
2023-03-01 01:16:34 +08:00
|
|
|
|
}
|
2023-03-15 19:39:12 +08:00
|
|
|
|
if (!camArm)
|
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
camArm = GetComponentInChildren<CameraArm>();
|
2023-03-15 19:39:12 +08:00
|
|
|
|
pat.prevTargetOffSet = camArm.TargetOffset;
|
|
|
|
|
}
|
2022-11-02 17:31:57 +08:00
|
|
|
|
|
2023-03-16 17:14:57 +08:00
|
|
|
|
if (jumpPadDrop && currentState == RaccoonStates.FALLING)
|
|
|
|
|
{
|
|
|
|
|
dropTimer += Time.DeltaTimeF;
|
|
|
|
|
if (dropTimer > dropDuration)
|
|
|
|
|
{
|
|
|
|
|
jumpPadDrop = false;
|
|
|
|
|
dropTimer = 0.0f;
|
|
|
|
|
currMoveVel = walkMaxMoveVel;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-02 17:31:57 +08:00
|
|
|
|
|
2023-02-21 19:31:50 +08:00
|
|
|
|
GotCaught();
|
2022-11-21 00:12:09 +08:00
|
|
|
|
Rotation();
|
2023-02-04 02:05:32 +08:00
|
|
|
|
MoveKey();
|
|
|
|
|
Sprint();
|
2022-11-25 22:53:38 +08:00
|
|
|
|
Jump();
|
2023-03-14 17:18:52 +08:00
|
|
|
|
|
2022-11-14 19:05:48 +08:00
|
|
|
|
//Debug.Log($"{currentState}");
|
|
|
|
|
//Debug.Log($" axisX: {axisMove.x} axisY:{axisMove.y}");
|
2022-11-16 22:28:08 +08:00
|
|
|
|
//Debug.Log($"X: {rb.LinearVelocity.x}" + $" Z: {rb.LinearVelocity.z}");
|
2022-11-01 23:28:31 +08:00
|
|
|
|
//Debug.Log(currentState.ToString() + " x:" + rb.LinearVelocity.x.ToString() + " y:" + rb.LinearVelocity.y.ToString() + " z:" + rb.LinearVelocity.z.ToString());
|
2023-02-21 19:31:50 +08:00
|
|
|
|
|
2022-11-01 13:24:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void fixedUpdate()
|
|
|
|
|
{
|
2023-03-02 17:33:02 +08:00
|
|
|
|
if (GameManager.Instance.GamePause || !GameManager.Instance.stealFoodPopUpDone)
|
2023-02-21 19:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 17:49:01 +08:00
|
|
|
|
Move();
|
|
|
|
|
Gravity();
|
2022-10-30 23:59:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 13:24:14 +08:00
|
|
|
|
|
2022-11-01 01:31:13 +08:00
|
|
|
|
private void MoveKey()
|
2022-10-30 23:59:35 +08:00
|
|
|
|
{
|
2022-11-03 01:50:02 +08:00
|
|
|
|
axisMove = Vector2.Zero;
|
2022-10-30 23:59:35 +08:00
|
|
|
|
if (Input.GetKey(Input.KeyCode.W))
|
2022-11-02 17:31:57 +08:00
|
|
|
|
{
|
|
|
|
|
Vector3 camerAixs = cam.GetForward();
|
|
|
|
|
camerAixs.y = 0;
|
|
|
|
|
camerAixs.Normalise();
|
2022-11-03 01:50:02 +08:00
|
|
|
|
axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
2022-11-02 17:31:57 +08:00
|
|
|
|
}
|
2022-11-14 19:05:48 +08:00
|
|
|
|
|
2022-11-02 17:31:57 +08:00
|
|
|
|
if (Input.GetKey(Input.KeyCode.S))
|
|
|
|
|
{
|
|
|
|
|
Vector3 camerAixs = cam.GetForward();
|
|
|
|
|
camerAixs.y = 0;
|
|
|
|
|
camerAixs.Normalise();
|
2022-11-03 01:50:02 +08:00
|
|
|
|
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
2022-11-02 17:31:57 +08:00
|
|
|
|
}
|
2022-11-14 19:05:48 +08:00
|
|
|
|
|
2022-11-02 17:31:57 +08:00
|
|
|
|
if (Input.GetKey(Input.KeyCode.A))
|
|
|
|
|
{
|
|
|
|
|
Vector3 camerAixs = cam.GetRight();
|
|
|
|
|
camerAixs.y = 0;
|
|
|
|
|
camerAixs.Normalise();
|
2022-11-03 01:50:02 +08:00
|
|
|
|
axisMove -= new Vector2(camerAixs.x, camerAixs.z);
|
2022-11-02 17:31:57 +08:00
|
|
|
|
}
|
2022-11-14 19:05:48 +08:00
|
|
|
|
|
2022-11-02 17:31:57 +08:00
|
|
|
|
if (Input.GetKey(Input.KeyCode.D))
|
|
|
|
|
{
|
|
|
|
|
Vector3 camerAixs = cam.GetRight();
|
|
|
|
|
camerAixs.y = 0;
|
|
|
|
|
camerAixs.Normalise();
|
2022-11-03 01:50:02 +08:00
|
|
|
|
axisMove += new Vector2(camerAixs.x, camerAixs.z);
|
2022-11-02 17:31:57 +08:00
|
|
|
|
}
|
2022-11-14 19:05:48 +08:00
|
|
|
|
|
2022-11-03 01:50:02 +08:00
|
|
|
|
axisMove.Normalise();
|
2022-11-17 00:23:38 +08:00
|
|
|
|
isMoveKeyPress = axisMove.x != 0 || axisMove.y != 0;
|
2022-11-01 01:31:13 +08:00
|
|
|
|
|
2022-11-13 21:56:28 +08:00
|
|
|
|
if (isMoveKeyPress && isGrounded && !Input.GetKey(Input.KeyCode.LeftShift))
|
2022-11-11 14:17:47 +08:00
|
|
|
|
{
|
2022-10-31 16:45:47 +08:00
|
|
|
|
currentState = RaccoonStates.WALKING;
|
2022-11-13 21:56:28 +08:00
|
|
|
|
|
2022-11-20 16:27:39 +08:00
|
|
|
|
if(stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerWalkState));
|
2022-11-11 14:17:47 +08:00
|
|
|
|
}
|
2022-10-31 16:45:47 +08:00
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
if (!isMoveKeyPress && isGrounded)
|
2022-11-11 14:17:47 +08:00
|
|
|
|
{
|
|
|
|
|
currentState = RaccoonStates.IDLE;
|
2022-11-13 21:56:28 +08:00
|
|
|
|
|
2022-11-20 16:27:39 +08:00
|
|
|
|
if(stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerIdleState));
|
2022-11-11 14:17:47 +08:00
|
|
|
|
}
|
2022-11-01 01:31:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Move()
|
|
|
|
|
{
|
2023-03-23 16:49:41 +08:00
|
|
|
|
if (rb && currentState != RaccoonStates.CAUGHT)
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2022-11-16 22:28:08 +08:00
|
|
|
|
rb.LinearVelocity += new Vector3(axisMove.x * moveForce, 0.0f, axisMove.y * moveForce) * Time.DeltaTimeF;
|
2022-11-15 18:52:46 +08:00
|
|
|
|
|
2023-03-23 16:49:41 +08:00
|
|
|
|
if (isMoveKeyPress)
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
Vector3 velNor = rb.LinearVelocity;
|
|
|
|
|
velNor.y = 0.0f;
|
2023-03-16 17:14:57 +08:00
|
|
|
|
if (jumpPadDrop)
|
|
|
|
|
currMoveVel = jumpPadMaxMoveVel;
|
|
|
|
|
else
|
|
|
|
|
currMoveVel = walkMaxMoveVel;
|
|
|
|
|
|
|
|
|
|
if (velNor.GetMagnitude() > currMoveVel)
|
2022-11-01 17:49:01 +08:00
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
velNor.Normalise();
|
2023-03-16 17:14:57 +08:00
|
|
|
|
velNor *= currMoveVel;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
rb.LinearVelocity = new Vector3(velNor.x, rb.LinearVelocity.y, velNor.z);
|
2022-11-01 17:49:01 +08:00
|
|
|
|
}
|
2022-10-31 16:45:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Sprint()
|
|
|
|
|
{
|
2022-11-01 23:28:31 +08:00
|
|
|
|
if (Input.GetKey(Input.KeyCode.LeftShift) && isMoveKeyPress && isGrounded)
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2022-11-01 01:31:13 +08:00
|
|
|
|
currentState = RaccoonStates.RUNNING;
|
2022-11-20 16:27:39 +08:00
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerRunState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerRunState));
|
2022-11-14 19:05:48 +08:00
|
|
|
|
|
2022-11-02 17:31:57 +08:00
|
|
|
|
holdItem = false;
|
|
|
|
|
if (!sprintIncreaseOnce)
|
2022-11-01 13:24:14 +08:00
|
|
|
|
{
|
|
|
|
|
sprintIncreaseOnce = true;
|
|
|
|
|
oldForce = moveForce;
|
2022-11-01 17:49:01 +08:00
|
|
|
|
moveForce *= sprintMultiplier;
|
2022-11-01 13:24:14 +08:00
|
|
|
|
|
2023-03-16 17:14:57 +08:00
|
|
|
|
maxOldVel = walkMaxMoveVel;
|
|
|
|
|
walkMaxMoveVel *= sprintMultiplier;
|
2022-11-01 13:24:14 +08:00
|
|
|
|
}
|
2022-10-31 16:45:47 +08:00
|
|
|
|
}
|
2022-11-01 13:24:14 +08:00
|
|
|
|
|
2023-03-23 16:49:41 +08:00
|
|
|
|
if (Input.GetKey(Input.KeyCode.LeftShift) && !isMoveKeyPress && isGrounded)
|
|
|
|
|
{
|
|
|
|
|
currentState = RaccoonStates.IDLE;
|
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerIdleState));
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
if (Input.GetKeyUp(Input.KeyCode.LeftShift))
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2023-03-14 17:18:52 +08:00
|
|
|
|
if (isMoveKeyPress && isGrounded)
|
|
|
|
|
{
|
2022-11-01 13:24:14 +08:00
|
|
|
|
currentState = RaccoonStates.WALKING;
|
2023-03-14 17:18:52 +08:00
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerWalkState)))
|
2022-11-20 16:27:39 +08:00
|
|
|
|
stateMachine.SetState(typeof(PlayerWalkState));
|
2022-11-11 14:17:47 +08:00
|
|
|
|
}
|
2023-03-23 16:49:41 +08:00
|
|
|
|
else if (!isMoveKeyPress && isGrounded)
|
2023-03-14 17:18:52 +08:00
|
|
|
|
{
|
|
|
|
|
currentState = RaccoonStates.IDLE;
|
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerIdleState));
|
|
|
|
|
}
|
2022-11-01 13:24:14 +08:00
|
|
|
|
sprintIncreaseOnce = false;
|
|
|
|
|
moveForce = oldForce;
|
2023-03-16 17:14:57 +08:00
|
|
|
|
walkMaxMoveVel = maxOldVel;
|
2022-10-31 16:45:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Jump()
|
|
|
|
|
{
|
2022-11-11 14:17:47 +08:00
|
|
|
|
if (currentState == RaccoonStates.WALKING || currentState == RaccoonStates.RUNNING || currentState == RaccoonStates.IDLE)
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2023-02-18 22:21:23 +08:00
|
|
|
|
if ( (Input.GetKeyDown(Input.KeyCode.Space) || landedOnJumpPad ) && isGrounded && rb != null)
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2023-03-14 17:18:52 +08:00
|
|
|
|
isGrounded = false;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
currentState = RaccoonStates.JUMP;
|
2023-03-11 11:07:21 +08:00
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerJumpState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerJumpState));
|
2022-11-01 17:49:01 +08:00
|
|
|
|
Vector3 v = rb.LinearVelocity;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
v.y = initialJumpVel * 0.5f;
|
2022-11-13 21:56:28 +08:00
|
|
|
|
if (holdItem && pat != null && pat.item.GetScript<Item>() != null)
|
2022-11-04 17:31:53 +08:00
|
|
|
|
{
|
|
|
|
|
Item item = pat.item.GetScript<Item>();
|
2022-11-13 21:56:28 +08:00
|
|
|
|
if (item != null && item.currCategory == ItemCategory.LIGHT)
|
2022-11-04 17:31:53 +08:00
|
|
|
|
v.y *= lightMultiper;
|
2022-11-13 21:56:28 +08:00
|
|
|
|
if (item != null && item.currCategory == ItemCategory.MEDIUM)
|
2022-11-04 17:31:53 +08:00
|
|
|
|
v.y *= mediumMultiper;
|
2022-11-13 21:56:28 +08:00
|
|
|
|
if (item != null && item.currCategory == ItemCategory.HEAVY)
|
2022-11-04 17:31:53 +08:00
|
|
|
|
v.y *= heavyMultiper;
|
|
|
|
|
}
|
2023-02-18 22:21:23 +08:00
|
|
|
|
|
|
|
|
|
if (landedOnJumpPad)
|
|
|
|
|
{
|
|
|
|
|
v.y *= jumpPadMultiplayer;
|
|
|
|
|
landedOnJumpPad = false;
|
2023-03-16 17:14:57 +08:00
|
|
|
|
jumpPadDrop = true;
|
2023-03-25 02:38:56 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["JumpPad"].Play();
|
2023-02-18 22:21:23 +08:00
|
|
|
|
}
|
2023-03-25 02:38:56 +08:00
|
|
|
|
else
|
|
|
|
|
AudioHandler.audioClipHandlers["Jump"].Play();
|
|
|
|
|
|
2022-11-01 17:49:01 +08:00
|
|
|
|
rb.LinearVelocity = v;
|
2022-10-31 16:45:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-11 11:07:21 +08:00
|
|
|
|
if (!isGrounded && rb != null && (rb.LinearVelocity.y < 0.0f || Input.GetKeyUp(Input.KeyCode.Space)))
|
|
|
|
|
{
|
2022-11-01 23:28:31 +08:00
|
|
|
|
currentState = RaccoonStates.FALLING;
|
2023-03-11 11:07:21 +08:00
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerFallState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerFallState));
|
|
|
|
|
}
|
2022-11-14 19:05:48 +08:00
|
|
|
|
|
2022-10-30 23:59:35 +08:00
|
|
|
|
}
|
2022-10-31 16:45:47 +08:00
|
|
|
|
|
2022-11-01 01:31:13 +08:00
|
|
|
|
private void Rotation()
|
|
|
|
|
{
|
2023-03-02 00:02:18 +08:00
|
|
|
|
tranform.LocalEulerAngles = new Vector3(0.0f, tranform.LocalEulerAngles.y, 0.0f);
|
2022-11-21 00:12:09 +08:00
|
|
|
|
if (isMoveKeyPress && tranform && !isAiming)
|
2022-11-01 01:31:13 +08:00
|
|
|
|
{
|
|
|
|
|
Quaternion currentRotation = tranform.LocalRotation;
|
2023-03-05 02:51:11 +08:00
|
|
|
|
Quaternion targetRotation = Quaternion.Euler(0.0f, MathF.Atan2(axisMove.x,axisMove.y), 0.0f);
|
2022-11-24 01:08:08 +08:00
|
|
|
|
tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.FixedDeltaTime);
|
2022-11-21 00:12:09 +08:00
|
|
|
|
}
|
|
|
|
|
else if (camArm && tranform && isAiming)
|
|
|
|
|
{
|
|
|
|
|
Quaternion currentRotation = tranform.LocalRotation;
|
|
|
|
|
Quaternion targetRotation = Quaternion.Euler(0.0f, SHADE.Math.DegreesToRadians(camArm.Yaw + 180.0f), 0.0f);
|
2022-11-24 01:08:08 +08:00
|
|
|
|
tranform.LocalRotation = Quaternion.Slerp(currentRotation, targetRotation, rotationFactorPerFrame * (float)Time.FixedDeltaTime);
|
2022-11-01 01:31:13 +08:00
|
|
|
|
}
|
2023-03-02 00:02:18 +08:00
|
|
|
|
|
2022-11-01 01:31:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 17:49:01 +08:00
|
|
|
|
private void Gravity()
|
|
|
|
|
{
|
|
|
|
|
if (rb != null)
|
|
|
|
|
{
|
|
|
|
|
//check player vel.y if its close to zero its on the ground
|
2022-11-01 23:28:31 +08:00
|
|
|
|
if (SHADE.Math.CompareFloat(rb.LinearVelocity.y, 0.0f))
|
2022-11-14 19:05:48 +08:00
|
|
|
|
{
|
2022-11-01 17:49:01 +08:00
|
|
|
|
isGrounded = true;
|
2022-11-14 19:05:48 +08:00
|
|
|
|
if (currentState == RaccoonStates.FALLING)
|
2023-03-25 02:38:56 +08:00
|
|
|
|
{
|
|
|
|
|
AudioHandler.audioClipHandlers["Land"].Play();
|
2022-11-14 19:05:48 +08:00
|
|
|
|
currentState = RaccoonStates.LANDED;
|
2023-03-16 17:14:57 +08:00
|
|
|
|
jumpPadDrop = false;
|
|
|
|
|
dropTimer = 0.0f;
|
|
|
|
|
currMoveVel = walkMaxMoveVel;
|
2023-03-14 17:18:52 +08:00
|
|
|
|
playLandedAnimation = true;
|
2023-03-11 11:07:21 +08:00
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerLandState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerLandState));
|
|
|
|
|
}
|
2022-11-14 19:05:48 +08:00
|
|
|
|
}
|
2022-11-01 17:49:01 +08:00
|
|
|
|
else
|
|
|
|
|
isGrounded = false;
|
|
|
|
|
|
|
|
|
|
Vector3 v = rb.LinearVelocity;
|
|
|
|
|
|
|
|
|
|
if (isGrounded)
|
|
|
|
|
v.y = groundGravity;
|
2022-11-01 23:28:31 +08:00
|
|
|
|
else if (currentState == RaccoonStates.FALLING)
|
|
|
|
|
{
|
|
|
|
|
float prevYVel = v.y;
|
2023-03-16 17:14:57 +08:00
|
|
|
|
float newYVel = 0;
|
|
|
|
|
|
|
|
|
|
if (jumpPadDrop)
|
|
|
|
|
newYVel = v.y + (gravity * jumpPadFallMultipler * (float)Time.FixedDeltaTime);
|
|
|
|
|
else
|
|
|
|
|
newYVel = v.y + (gravity * fallMultipler * (float)Time.FixedDeltaTime);
|
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
float nextYVel = (prevYVel + newYVel) * 0.5f;
|
|
|
|
|
v.y = nextYVel;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
float prevYVel = v.y;
|
2022-11-24 01:08:08 +08:00
|
|
|
|
float newYVel = v.y + (gravity * (float)Time.FixedDeltaTime);
|
2022-11-01 23:28:31 +08:00
|
|
|
|
float nextYVel = (prevYVel + newYVel) * 0.5f;
|
|
|
|
|
v.y = nextYVel;
|
|
|
|
|
}
|
2022-11-01 17:49:01 +08:00
|
|
|
|
|
|
|
|
|
rb.LinearVelocity = v;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-04 17:31:53 +08:00
|
|
|
|
private void GotCaught()
|
|
|
|
|
{
|
2022-11-23 16:57:32 +08:00
|
|
|
|
if (currentState == RaccoonStates.CAUGHT && tranform && respawnPoint)
|
2022-11-04 17:31:53 +08:00
|
|
|
|
{
|
2023-03-25 02:38:56 +08:00
|
|
|
|
AudioHandler.audioClipHandlers["RaccoonCaught"].Play();
|
2022-11-11 14:17:47 +08:00
|
|
|
|
currentState = RaccoonStates.IDLE;
|
2022-11-20 16:27:39 +08:00
|
|
|
|
if (stateMachine && !stateMachine.IsState(typeof(PlayerIdleState)))
|
|
|
|
|
stateMachine.SetState(typeof(PlayerIdleState));
|
2022-11-23 16:57:32 +08:00
|
|
|
|
tranform.LocalPosition = respawnPoint.GetComponent<Transform>().LocalPosition;
|
2023-01-25 18:20:26 +08:00
|
|
|
|
|
2023-03-21 14:40:30 +08:00
|
|
|
|
GameManager.Instance.RacoonCaught();
|
|
|
|
|
|
2023-02-02 22:44:30 +08:00
|
|
|
|
if (pat && pat.item)
|
2023-01-25 18:20:26 +08:00
|
|
|
|
{
|
2023-03-05 15:35:57 +08:00
|
|
|
|
if (holdItem)
|
|
|
|
|
{
|
|
|
|
|
holdItem = false;
|
2023-03-23 16:49:41 +08:00
|
|
|
|
Debug.Log("PLAYER RETURN");
|
2023-03-05 15:35:57 +08:00
|
|
|
|
pat.item.GetScript<Item>().returnBack = true;
|
|
|
|
|
}
|
|
|
|
|
if (isAiming)
|
|
|
|
|
{
|
|
|
|
|
isAiming = false;
|
2023-03-08 17:00:43 +08:00
|
|
|
|
cam.FOV = Settings.cameraFOV;
|
2023-03-05 15:35:57 +08:00
|
|
|
|
camArm.TargetOffset = pat.prevTargetOffSet;
|
|
|
|
|
camArm.ArmLength = pat.tpc.armLength;
|
|
|
|
|
}
|
2023-01-25 18:20:26 +08:00
|
|
|
|
}
|
2022-11-04 17:31:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-01 13:24:14 +08:00
|
|
|
|
protected override void onCollisionEnter(CollisionInfo info)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-11 14:17:47 +08:00
|
|
|
|
}
|
2022-11-01 13:24:14 +08:00
|
|
|
|
|