Add jump ability

This commit is contained in:
Nico 2025-07-05 01:04:13 -07:00
parent cc316e263a
commit 39708027b4
9 changed files with 5141 additions and 73 deletions

View File

@ -71010,6 +71010,14 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1680573792925415762, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: VfxKineticSurge
value:
objectReference: {fileID: 4566952472781634859, guid: 0d7c4835b1f550241bb630daef9e33e8, type: 3}
- target: {fileID: 1680573792925415762, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: FighterClass.VfxKineticSurge
value:
objectReference: {fileID: 4566952472781634859, guid: 0d7c4835b1f550241bb630daef9e33e8, type: 3}
- target: {fileID: 1680573792925415762, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: 'ClassIndicators.Array.data[0]'
value:
@ -71026,6 +71034,10 @@ PrefabInstance:
propertyPath: 'ClassIndicators.Array.data[3]'
value:
objectReference: {fileID: 1731397399}
- target: {fileID: 1787569555844345674, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1825172400684165510, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: m_BodyType
value: 1
@ -71162,6 +71174,14 @@ PrefabInstance:
propertyPath: m_LocalPosition.y
value: -0.195
objectReference: {fileID: 0}
- target: {fileID: 9074809610135348735, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9098681062314285509, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 9117212351613092415, guid: d00d92ab204198c489965b31a298b234, type: 3}
propertyPath: m_Size.x
value: 0.84173715

View File

@ -1,7 +1,5 @@
using AI.Base;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using static TMPro.SpriteAssetUtilities.TexturePacker_JsonArray;
public class EnemyStateManager : StateManager {
[Header("States")]

View File

@ -52,10 +52,11 @@ public class AttackAnimatorFactory : MonoBehaviour {
}
public void MeleeResetKineticCharge() {
Melee.CrossFade("Blank", 0, 1);
//Melee.CrossFade("Blank", 0, 1);
}
public void MeleeBasic(int set) {
return;
RotateTowardsMouse();
if (set == 1) Melee.CrossFade("BasicAttack1", 0, 0);
@ -68,6 +69,7 @@ public class AttackAnimatorFactory : MonoBehaviour {
}
public void MeleeKineticSurge() {
return;
Melee.CrossFade("KineticSurgeRelease", 0, 0);
}
}

View File

@ -19,7 +19,7 @@ public class ClassBase {
protected float PlayerOriginalSpeed;
protected FloatingTextSpawner TextPopUp;
/// <summary>Always in the order of Up, Down, Left, Right</summary>
public string AnimationToPlay;
public string AnimationToPlay = "";
public ClassBase(Player player) {
Player = player;
@ -29,6 +29,6 @@ public class ClassBase {
}
virtual public void Tick() { }
virtual public void HandleLMB() { }
virtual public void HandleRMB() { }
virtual public void HandlePrimaryAttack() { }
virtual public void HandleSecondaryAttack() { }
}

View File

@ -1,16 +1,7 @@
using JetBrains.Annotations;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor.VersionControl;
using UnityEngine;
using UnityEngine;
[System.Serializable]
public class MeleeFighterClass : ClassBase {
public MeleeFighterClass(Player player) : base(player) { }
private readonly int BladeVortex = Animator.StringToHash("BladeVortex");
private float BladeVortexSpeed = 0.4f;
public float ComboResetTime;
@ -22,6 +13,15 @@ public class MeleeFighterClass : ClassBase {
public float TimeElapsed;
public float Cooldown;
public bool TimesUp;
private bool HandlingOnStateEnter;
public VfxHandlerBase VfxKineticSurgeHandler { get { return Player.VfxKineticSurgeHandler; } }
public MeleeFighterClass(Player player) : base(player) {
}
public AttackState CurrentState;
@ -77,11 +77,11 @@ public class MeleeFighterClass : ClassBase {
AnimationToPlay = "Attack1";
TextPopUp.SpawnFloatingText("KineticSurge", Color.red, 3);
//Player.SkillInUse = false;
Player.MoveSpeed = PlayerOriginalSpeed;
//Player.MoveSpeed = PlayerOriginalSpeed;
}
if (!ChargingAnAttack && TimesUp) {
Player.MoveSpeed = PlayerOriginalSpeed;
Player.MoveSpeedDampener = 1;
ChangeState(AttackState.None);
AttackAnimator.MeleeResetKineticCharge();
Player.SkillInUse = false;
@ -109,12 +109,12 @@ public class MeleeFighterClass : ClassBase {
override public void HandleLMB() {
override public void HandlePrimaryAttack() {
Player.SkillInUse = true;
switch (CurrentState) {
case AttackState.None:
PlayerOriginalSpeed = Player.MoveSpeed;
//PlayerOriginalSpeed = Player.MoveSpeed;
if ((Time.time - Player.DashTime) <= 0.1f)
ChangeState(AttackState.PhaseCleave, 1.5f);
@ -122,7 +122,6 @@ public class MeleeFighterClass : ClassBase {
ChangeState(AttackState.Shockwave, 0, 1.5f);
else
ChangeState(AttackState.BasicAttack1, 0.35f);
break;
@ -135,16 +134,18 @@ public class MeleeFighterClass : ClassBase {
ChangeState(AttackState.BasicAttack3, 0.15f);
break;
}
}
override public void HandleRMB() {
override public void HandleSecondaryAttack() {
Player.SkillInUse = true;
switch (CurrentState) {
case AttackState.None:
PlayerOriginalSpeed = Player.MoveSpeed;
/*PlayerOriginalSpeed = Player.MoveSpeed*/
if (Player.IsDashing)
ChangeState(AttackState.None);
@ -165,6 +166,12 @@ public class MeleeFighterClass : ClassBase {
case AttackState.BasicAttack3:
//ChangeState(AttackState.ChargeSurgeB);
break;
case AttackState.BladeVortex:
ChangeState(AttackState.None);
//ChangeState(AttackState.ChargeSurgeB);
break;
}
}
@ -177,12 +184,14 @@ public class MeleeFighterClass : ClassBase {
if (TimeElapsed < Cooldown) return;
CurrentState = state;
Player.MoveSpeedDampener = (state == AttackState.None) ? 1 : 1 / decreasedSpeed;
if (state == AttackState.None) return;
Cooldown = cooldown;
TextPopUp.SpawnFloatingText(state.ToString(), Color.red, 3);
ComboResetTime = resetTime;
LastComboTime = Time.time;
Player.MoveSpeed = (state == AttackState.None) ? PlayerOriginalSpeed : PlayerOriginalSpeed * decreasedSpeed;
RotateTowardsMouse();
switch (CurrentState) {
case AttackState.None:
@ -197,7 +206,6 @@ public class MeleeFighterClass : ClassBase {
case AttackState.BladeVortex:
AnimationToPlay = "BladeVortex_";
//Animator.CrossFade(BladeVortex, 0);
break;
case AttackState.BasicAttack1:
@ -215,13 +223,20 @@ public class MeleeFighterClass : ClassBase {
AttackAnimator.MeleeBasic(3);
break;
case AttackState.KineticSurgeA:
Debug.Log($"Charged Value: {ChargeValue}");
break;
case AttackState.KineticSurgeB:
Debug.Log($"Charged Value: {ChargeValue}");
case AttackState.KineticSurgeRelease:
VfxKineticSurgeHandler.PlayAll(Player.transform.position);
break;
}
}
public void RotateTowardsMouse() {
return;
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 direction = mouseWorldPos - Player.transform.position;
if (Mathf.Abs(direction.x) > Mathf.Abs(direction.y)) {
Player.LastDirection = (direction.x > 0) ? Player.Direction.Right : Player.Direction.Left;
} else {
Player.LastDirection = (direction.y > 0) ? Player.Direction.Up : Player.Direction.Down;
}
}
}

View File

@ -1,11 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[SelectionBase]
@ -25,17 +21,21 @@ public class Player : MonoBehaviour {
[SerializeField] private MeleeFighterClass FighterClass;
public AttackAnimatorFactory AttackAnimator;
[Header("Movement Attributes")]
[SerializeField] public float MoveSpeed = 8;
[SerializeField] public float MoveSpeedDampener = 1;
[SerializeField] private float DashMultiplier = 60;
[SerializeField] private float DriftSpeed = 60;
[SerializeField] private float DriftFactorial = 0.85f;
[SerializeField] private float JumpDelay = 0.5f;
[Header("VFX")]
[SerializeField] private GameObject VfxDash;
private VfxHandlerBase VfxDashHandler;
[SerializeField] private GameObject VfxKineticSurge;
[HideInInspector] public VfxHandlerBase VfxKineticSurgeHandler;
private BoxCollider2D[] BoxColliders;
public Vector2 PrevDirection = Vector2.zero;
@ -48,22 +48,16 @@ public class Player : MonoBehaviour {
public Vector2 DriftDirection { get; private set; } = Vector2.zero;
private float Drift = 0;
private readonly int AnimMoveRight = Animator.StringToHash("Anim_Player_MoveRight");
private readonly int AnimIdleRight = Animator.StringToHash("Anim_Player_IdleRight");
public bool SkillInUse = false;
//{
// get { return Animator.GetBool("SkillActive"); }
// set { Animator.SetBool("SkillActive", value); }
//}
private enum Directions { Left, Right, Up, Down }
void Awake() {
Builder = GetComponent<BuilderManager>();
VfxDashHandler = new VfxHandlerBase(VfxDash, 5, 5);
VfxKineticSurgeHandler = new VfxHandlerBase(VfxKineticSurge, 5, 5);
FighterClass = new MeleeFighterClass(this);
BoxColliders = GetComponentsInChildren<BoxCollider2D>();
SetClass(1);
}
@ -72,6 +66,7 @@ public class Player : MonoBehaviour {
KeyPressActions();
ActiveClass.Tick();
}
private void GatherInput() {
MoveDirection.x = Input.GetAxisRaw("Horizontal");
MoveDirection.y = Input.GetAxisRaw("Vertical");
@ -80,6 +75,8 @@ public class Player : MonoBehaviour {
private void KeyPressActions() {
if (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)) {
Dash(MoveDirection);
} else if (!IsJumping && Input.GetKeyDown(KeyCode.Space)) {
Jump();
} else if (Input.GetKeyDown(KeyCode.F1)) {
SetClass(0);
} else if (Input.GetKeyDown(KeyCode.F2)) {
@ -90,17 +87,17 @@ public class Player : MonoBehaviour {
SetClass(3);
}
if (Input.GetMouseButtonDown(0)) ActiveClass.HandleLMB();
else if (Input.GetMouseButtonDown(1)) ActiveClass.HandleRMB();
if (Input.GetKeyDown(KeyCode.X)) ActiveClass.HandlePrimaryAttack();
else if (Input.GetKeyDown(KeyCode.C)) ActiveClass.HandleSecondaryAttack();
}
private void Dash(Vector2 direction) {
if (SkillInUse) return;
if (Drift > 0.5f) return;
IsDashing = true;
DashTime = Time.time;
RigidBody.linearVelocity = direction.normalized * MoveSpeed * DashMultiplier;
RigidBody.linearVelocity = (direction.normalized * MoveSpeed * DashMultiplier) / MoveSpeedDampener;
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg + 180;
if (direction.normalized != Vector2.zero)
VfxDashHandler.PlayAll(this.transform.position, Quaternion.Euler(0f, 0f, angle));
@ -109,6 +106,22 @@ public class Player : MonoBehaviour {
IsDashing = false;
}
private void Jump() {
IsJumping = true;
foreach (var col in BoxColliders)
col.enabled = false;
StartCoroutine(ResetJumpAfterDelay());
}
private IEnumerator ResetJumpAfterDelay() {
yield return new WaitForSeconds(JumpDelay);
foreach (var col in BoxColliders)
col.enabled = true;
IsJumping = false;
}
private void SetClass(int classIdx) {
Builder.SetBuildMode(classIdx == 3);
ActiveClass = FighterClass;
@ -138,7 +151,7 @@ public class Player : MonoBehaviour {
private void MovementUpdate() {
if (IsDashing) return;
RigidBody.linearVelocity = MoveDirection.normalized * MoveSpeed;
RigidBody.linearVelocity = (MoveDirection.normalized * MoveSpeed) / MoveSpeedDampener;
if (Drift > 0.2f) {
RigidBody.linearVelocity += DriftDirection * Drift;
Drift *= DriftFactorial;
@ -165,41 +178,49 @@ public class Player : MonoBehaviour {
Animator.CrossFade(state, 0);
}
private enum Direction { Up, Down, Left, Right }
private Direction LastDirection = Direction.Down;
public enum Direction { Up, Down, Left, Right }
public Direction LastDirection = Direction.Down;
private string GetAnimationState(Vector2 input) {
if (SkillInUse) return ActiveClass.AnimationToPlay;
if (!IsJumping && input.sqrMagnitude < 0.01f) return "Idle";
if (input.sqrMagnitude < 0.01f) {
return "Idle";
//return LastDirection switch {
// Direction.Up => "IdleUp",
// Direction.Down => "IdleDown",
// Direction.Left => "IdleLeft",
// Direction.Right => "IdleRight",
// _ => "IdleDown"
//};
}
if (Mathf.Abs(input.x) > Mathf.Abs(input.y)) {
if (Mathf.Abs(input.x) > 0)
LastDirection = (input.x > 0) ? Direction.Right : Direction.Left;
} else {
else if (Mathf.Abs(input.y) > 0)
LastDirection = (input.y > 0) ? Direction.Up : Direction.Down;
}
if (IsJumping) return "Jump";
return "Run";
return LastDirection switch {
Direction.Up => "RunUp",
Direction.Down => "RunDown",
Direction.Left => "RunLeft",
Direction.Right => "RunRight",
_ => "RunDown"
};
}
void OnDrawGizmos() {
DrawPlayerDirection();
}
private void DrawPlayerDirection() {
if (RigidBody == null) RigidBody = GetComponent<Rigidbody2D>();
if (RigidBody == null) return;
Gizmos.color = Color.cyan;
Vector3 start = RigidBody.transform.position;
Vector3 end = start + (Vector3)(RigidBody.linearVelocity * 1);
Gizmos.DrawLine(start, end);
DrawArrowHead(end, (end - start).normalized);
}
void DrawArrowHead(Vector3 position, Vector3 direction) {
float arrowHeadAngle = 20f;
float arrowHeadLength = 0.25f;
Vector3 right = Quaternion.Euler(0, 0, arrowHeadAngle) * -direction;
Vector3 left = Quaternion.Euler(0, 0, -arrowHeadAngle) * -direction;
Gizmos.DrawLine(position, position + right * arrowHeadLength);
Gizmos.DrawLine(position, position + left * arrowHeadLength);
}
}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fb178844c7bd9184982b533840dc48d4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0d7c4835b1f550241bb630daef9e33e8
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: