2022-10-30 23:59:35 +08:00
|
|
|
|
using SHADE;
|
|
|
|
|
using System;
|
2022-11-10 13:06:37 +08:00
|
|
|
|
using System.Collections.Generic;
|
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-23 16:57:32 +08:00
|
|
|
|
/* public enum WalkingState
|
2022-11-10 13:06:37 +08:00
|
|
|
|
{
|
|
|
|
|
CARRY,
|
|
|
|
|
AIMING,
|
|
|
|
|
THROW,
|
|
|
|
|
WALK,
|
|
|
|
|
TOTAL
|
2022-11-23 16:57:32 +08:00
|
|
|
|
}*/
|
2022-11-10 13:06:37 +08:00
|
|
|
|
|
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-01-25 18:20:26 +08:00
|
|
|
|
public StateMachine stateMachine;
|
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")]
|
2022-11-11 14:17:47 +08:00
|
|
|
|
public RaccoonStates currentState = RaccoonStates.IDLE;
|
2022-10-31 16:45:47 +08:00
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
//Movement variables============================================================
|
|
|
|
|
[Tooltip("Max vel for walking")]
|
2022-11-23 20:48:40 +08:00
|
|
|
|
public float maxMoveVel = 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
|
|
|
|
|
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;
|
|
|
|
|
|
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)
|
2022-10-30 23:59:35 +08:00
|
|
|
|
Debug.LogError("RigidBody is NULL!");
|
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)
|
2022-11-01 01:31:13 +08:00
|
|
|
|
Debug.LogError("tranform is NULL!");
|
|
|
|
|
|
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>();
|
2022-11-20 16:27:39 +08:00
|
|
|
|
dictionary.Add(typeof(PlayerIdleState), new PlayerIdleState(stateMachine));
|
|
|
|
|
dictionary.Add(typeof(PlayerWalkState), new PlayerWalkState(stateMachine));
|
|
|
|
|
dictionary.Add(typeof(PlayerRunState), new PlayerRunState(stateMachine));
|
|
|
|
|
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
|
|
|
|
|
2022-10-30 23:59:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
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-02-21 19:31:50 +08:00
|
|
|
|
if (GameManager.Instance.GamePause)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 16:57:32 +08:00
|
|
|
|
if (delayTimer <= 1)
|
|
|
|
|
delayTimer += Time.DeltaTimeF;
|
|
|
|
|
|
|
|
|
|
if (delayTimer < 1)
|
|
|
|
|
{
|
|
|
|
|
if (tranform && respawnPoint && rb)
|
|
|
|
|
{
|
|
|
|
|
rb.LinearVelocity = Vector3.Zero;
|
|
|
|
|
tranform.LocalPosition = respawnPoint.GetComponent<Transform>().LocalPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rb.FreezePositionY = false;
|
|
|
|
|
}
|
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)
|
2022-11-02 17:31:57 +08:00
|
|
|
|
cam = GetComponentInChildren<Camera>();
|
2022-11-21 00:12:09 +08:00
|
|
|
|
if(!camArm)
|
|
|
|
|
camArm = GetComponentInChildren<CameraArm>();
|
2022-11-02 17:31:57 +08:00
|
|
|
|
|
2023-02-04 14:11:16 +08:00
|
|
|
|
//tempFix
|
|
|
|
|
if (tranform)
|
|
|
|
|
tranform.LocalEulerAngles = new Vector3(0.0f, tranform.LocalEulerAngles.y, 0.0f);
|
|
|
|
|
|
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();
|
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-02-21 19:31:50 +08:00
|
|
|
|
if (GameManager.Instance.GamePause)
|
|
|
|
|
{
|
|
|
|
|
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-02-21 19:31:50 +08:00
|
|
|
|
if (rb != null && 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
|
|
|
|
|
2022-11-21 00:12:09 +08:00
|
|
|
|
if (isMoveKeyPress && rb)
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
Vector3 velNor = rb.LinearVelocity;
|
|
|
|
|
velNor.y = 0.0f;
|
|
|
|
|
if (velNor.GetMagnitude() > maxMoveVel)
|
2022-11-01 17:49:01 +08:00
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
velNor.Normalise();
|
|
|
|
|
velNor *= maxMoveVel;
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
maxOldVel = maxMoveVel;
|
2022-11-01 17:49:01 +08:00
|
|
|
|
maxMoveVel *= 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
|
|
|
|
|
2022-11-01 23:28:31 +08:00
|
|
|
|
if (Input.GetKeyUp(Input.KeyCode.LeftShift))
|
2022-10-31 16:45:47 +08:00
|
|
|
|
{
|
2022-11-11 14:17:47 +08:00
|
|
|
|
if (isMoveKeyPress)
|
|
|
|
|
{
|
2022-11-01 13:24:14 +08:00
|
|
|
|
currentState = RaccoonStates.WALKING;
|
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-11-01 13:24:14 +08:00
|
|
|
|
sprintIncreaseOnce = false;
|
|
|
|
|
moveForce = oldForce;
|
|
|
|
|
maxMoveVel = 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
|
|
|
|
{
|
2022-11-01 23:28:31 +08:00
|
|
|
|
currentState = RaccoonStates.JUMP;
|
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;
|
|
|
|
|
}
|
2022-11-01 17:49:01 +08:00
|
|
|
|
rb.LinearVelocity = v;
|
2022-10-31 16:45:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 19:05:48 +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;
|
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()
|
|
|
|
|
{
|
2022-11-21 00:12:09 +08:00
|
|
|
|
if (isMoveKeyPress && tranform && !isAiming)
|
2022-11-01 01:31:13 +08:00
|
|
|
|
{
|
|
|
|
|
Quaternion currentRotation = tranform.LocalRotation;
|
2022-11-21 00:12:09 +08:00
|
|
|
|
Quaternion targetRotation = Quaternion.LookRotation(new Vector3(axisMove.x, 0.0f, axisMove.y), new Vector3(0.0f, 1.0f, 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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
currentState = RaccoonStates.LANDED;
|
|
|
|
|
}
|
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;
|
2022-11-24 01:08:08 +08:00
|
|
|
|
float 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
|
|
|
|
{
|
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-02-02 22:44:30 +08:00
|
|
|
|
if (pat && pat.item)
|
2023-01-25 18:20:26 +08:00
|
|
|
|
{
|
|
|
|
|
holdItem = false;
|
|
|
|
|
isAiming = false;
|
|
|
|
|
pat.item.GetScript<Item>().returnBack = true;
|
|
|
|
|
}
|
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
|
|
|
|
|