-
-
Save IneonInoodle/ae6577b8b4a8e65749055b8128a8fa75 to your computer and use it in GitHub Desktop.
3rd person controller for shaman saga
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections.Generic; | |
[RequireComponent(typeof(Rigidbody))] | |
[RequireComponent(typeof(CapsuleCollider))] | |
// controls movement , animation and player states. | |
public class PlayerStateManager : MonoBehaviour, IDamageable | |
{ | |
public enum PlayerState | |
{ | |
walking, idle, dashing, stunned, falling, meleeAttackingStart, meleeAttacking, meleeAttackingEnd, groundPounding, lightShooting, piercingShooting | |
} | |
//public SkinnedMeshRenderer firstRenderer; | |
//public SkinnedMeshRenderer secondRenderer; | |
//private Color firstOriginalColor; | |
//private Color secondOriginalColor; | |
public float flashTime = 1f; | |
public bool canChangeStates; | |
public PlayerState state; | |
[Header("Init")] | |
public GameObject activeModel; | |
[Header("Inputs")] | |
public bool meleeInput; | |
public bool dashInput; | |
public bool groundPoundInput; | |
public bool lightShotInput; | |
public bool pierceingShotInput; | |
public bool swapInput; | |
public bool rt, lt, a, b, x, y, rb; | |
public float vertical; | |
public float horizontal; | |
public float moveAmount; | |
public float rotateAmount; | |
public Vector3 moveDir; | |
public Vector3 lookDir; | |
public float verticalR; | |
public float horizontalR; | |
public bool itemInput; | |
[Header("Stats")] | |
public bool canMove = true; | |
public bool onEmpty = true; | |
public bool onEmpty2 = true; | |
public bool usingMouse = false; | |
public float moveSpeed = 5f; | |
public float rotateSpeed = 20; | |
public float rollSpeed = 1; | |
public float aimRotateSpeed = 0.7f; | |
public float MovementAnimationSpeed = 1.2f; | |
public float comboTime; | |
public float stunTime = 0.01f; | |
public AnimationCurve roll_curve; | |
public float animDampTime = 0f; | |
public float groundCheckDistance = 1f; | |
public Vector3 m_GroundNormal; | |
Vector3 lookPos; // for mouse | |
Vector3 targetDir; // for joystick | |
[Header("States")] //REMOVE THESE | |
public bool rolling; // any movement ability here | |
public bool onGround; | |
public bool holdingShoot; | |
public bool holdingLightShoot; | |
public bool inAction; | |
public bool usingItem; | |
public bool takeDamage; | |
public bool damageCollidersOpen; | |
public bool teleporting = false; | |
[Header("Melee Attack")] | |
public float lightAttackDamage = 50; | |
public float groundSlamAttackDamage = 150; | |
public float groundSlamAttackRadius = 5; | |
public GameObject groundSlamParticleEffect; | |
public float groundSlamCoolDown = 3f; | |
[Header("Raycast")] | |
public LayerMask ignoreLayers; | |
[Header("Weapon Stuff")] | |
[HideInInspector] | |
public Animator anim; | |
[HideInInspector] | |
public Rigidbody rigid; | |
[HideInInspector] | |
public CapsuleCollider m_Capsule; | |
[HideInInspector] | |
public float delta; | |
[HideInInspector] | |
float m_CapsuleHeight; | |
[HideInInspector] | |
Vector3 m_CapsuleCenter; | |
[HideInInspector] | |
public KE.AnimatorHook a_hook; | |
[HideInInspector] | |
public KE.ActionManager actionManager; | |
[HideInInspector] | |
public KE.InventoryManager inventoryManager; | |
[HideInInspector] | |
public KE.ActionInput storePrevAction; | |
public KE.ActionInput storeActionInput; | |
private float startY = 0; | |
float _comboTimer; | |
float _groundPoundCooldownTimer; | |
float _actionDelay; | |
float stunnedTimer; | |
bool tookDamageFromEnemy = false; // this is set to true after the enemy has attack and now the player should being their stunned phase. | |
bool groundPounded = false; | |
bool holdingLightMeleeInput = false; | |
public KE.Weapon myWeapon; | |
public void Init() | |
{ | |
startY = this.transform.position.y; | |
myWeapon = GetComponent<KE.InventoryManager>().curWeapon;//remove weapons | |
//Cursor.visible = false; | |
SetupAnimator(); | |
rigid = GetComponent<Rigidbody>(); | |
m_Capsule = GetComponent<CapsuleCollider>(); | |
m_CapsuleHeight = m_Capsule.height; | |
m_CapsuleCenter = m_Capsule.center; | |
//if (a_hook != activeModel.AddComponent<KE.AnimatorHook>();) | |
Destroy(a_hook); | |
a_hook = activeModel.AddComponent<KE.AnimatorHook>(); | |
a_hook.Init(this, null); | |
//inventory before action manager or else RIP | |
inventoryManager = GetComponent<KE.InventoryManager>(); // remove this | |
inventoryManager.Init(); | |
actionManager = GetComponent<KE.ActionManager>(); // remove this | |
actionManager.Init(this); | |
rigid.angularDrag = 999;//always max angulardrag for all things | |
rigid.drag = 4; | |
rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; | |
//gameObject.layer = 8; | |
anim.SetBool("onGround", true); | |
} | |
void SetupAnimator() | |
{ | |
anim = GetComponentInChildren<Animator>(); | |
if (anim == null) | |
{ | |
Debug.LogError("No Animator Found on active model"); | |
} | |
else | |
{ | |
activeModel = anim.gameObject; | |
} | |
anim.applyRootMotion = false; | |
anim.SetBool("lightMode", gameObject.GetComponent<Player>().lightMode == LightMode.purple? true:false); | |
} | |
//public void DoChangeStates(newstate ) | |
public void changeStates() //checks to see if we should switch to a different state using our current state | |
{ | |
switch (state) | |
{ | |
case PlayerState.idle: | |
if (moveAmount > 0 || lookDir != Vector3.zero) | |
state = PlayerState.walking; | |
if (dashInput) | |
{ | |
if(GetComponent<Player>().lightMode == LightMode.purple) | |
state = PlayerState.dashing; | |
} | |
if (lightShotInput) | |
if (GetComponent<Player>().lightMode == LightMode.purple) | |
state = PlayerState.lightShooting; | |
if (pierceingShotInput) | |
if (GetComponent<Player>().lightMode == LightMode.purple) | |
state = PlayerState.piercingShooting; | |
if (groundPoundInput) | |
if (GetComponent<Player>().lightMode == LightMode.yellow) | |
{ | |
state = PlayerState.groundPounding; | |
} | |
if (meleeInput) | |
if (GetComponent<Player>().lightMode == LightMode.yellow) | |
{ | |
state = PlayerState.meleeAttackingStart; | |
} | |
if (onGround == false) | |
{ | |
state = PlayerState.falling; | |
} | |
if (tookDamageFromEnemy) | |
{ | |
if (GetComponent<Player>().lightMode != LightMode.yellow) | |
state = PlayerState.stunned; | |
} | |
break; | |
case PlayerState.falling: | |
if (onGround == true) | |
{ | |
state = PlayerState.idle; | |
} | |
break; | |
case PlayerState.walking: //main state which will switch to inbetween other states | |
if (moveAmount == 0 && lookDir == Vector3.zero) | |
state = PlayerState.idle; | |
if (dashInput) | |
{ | |
AudioManager.Main.PlayNewSound("RPlayerDash", AudioType.Sfx, gameObject); | |
if (GetComponent<Player>().lightMode == LightMode.purple) | |
{ | |
GameManager.Instance.uiParent.lightPlayerCoolDowns[2].GetComponent<CoolDown>().triggerCooldown(0.5f); | |
state = PlayerState.dashing; | |
} else | |
{ /* | |
GameManager.Instance.uiParent.darkPlayerCoolDowns[2].GetComponent<CoolDown>().triggerCooldown(0.5f); | |
state = PlayerState.dashing; | |
*/ | |
} | |
} | |
if (lightShotInput) | |
if (GetComponent<Player>().lightMode == LightMode.purple) | |
state = PlayerState.lightShooting; | |
if (pierceingShotInput) | |
if (GetComponent<Player>().lightMode == LightMode.purple) | |
state = PlayerState.piercingShooting; | |
if (groundPoundInput) | |
if (GetComponent<Player>().lightMode == LightMode.yellow) | |
state = PlayerState.groundPounding; | |
if (meleeInput) | |
if (GetComponent<Player>().lightMode == LightMode.yellow) | |
{ | |
Debug.Log("switching to melee"); | |
state = PlayerState.meleeAttackingStart; | |
} | |
if (onGround == false) | |
state = PlayerState.falling; | |
if (tookDamageFromEnemy) | |
{ | |
state = PlayerState.stunned; | |
} | |
break; | |
case PlayerState.dashing: // dashing state is over after animation stops playing | |
onEmpty = anim.GetBool("onEmpty"); | |
if (onEmpty == true) | |
{ | |
a_hook.CloseRoll(); | |
state = PlayerState.walking; | |
} | |
break; | |
case PlayerState.groundPounding: | |
onEmpty = anim.GetBool("onEmpty"); | |
onEmpty2 = anim.GetBool("onEmpty2");// ground state is over after animation stops playing | |
if (onEmpty == true) | |
state = PlayerState.walking; | |
break; | |
case PlayerState.stunned: // stunned state is over stunned timer completes | |
stunnedTimer += delta; | |
a_hook.CloseDamageColliders(); | |
if (stunnedTimer > stunTime) | |
{ | |
state = PlayerState.walking; | |
tookDamageFromEnemy = false; | |
stunnedTimer = 0; | |
} | |
break; | |
case PlayerState.meleeAttackingStart: // ends once the damage colliders on your sword open | |
if (damageCollidersOpen == true) | |
{ | |
state = PlayerState.meleeAttacking; | |
} | |
onEmpty2 = anim.GetBool("onEmpty2"); | |
if (onEmpty2 == true) | |
{ | |
state = PlayerState.walking; | |
} | |
break; | |
case PlayerState.meleeAttacking: // ends once the damage colliders on your sword close | |
if (damageCollidersOpen == false) { | |
state = PlayerState.meleeAttackingEnd; | |
} | |
onEmpty2 = anim.GetBool("onEmpty2"); | |
if (onEmpty2 == true) | |
{ | |
state = PlayerState.walking; | |
} | |
break; | |
case PlayerState.meleeAttackingEnd: // ends once attack animation has finished completely or if player moves causing animation cancel | |
_comboTimer = 0; // set timer to 0, starting it. | |
if (meleeInput) | |
if (GetComponent<Player>().lightMode == LightMode.yellow) | |
{ | |
Debug.Log("meleeing direct"); | |
state = PlayerState.meleeAttackingStart; | |
return; | |
} | |
onEmpty2 = anim.GetBool("onEmpty2"); | |
if (onEmpty2 == true) | |
{ | |
state = PlayerState.walking; | |
} | |
break; | |
case PlayerState.lightShooting: | |
if (lightShotInput == false) | |
state = PlayerState.idle; | |
break; | |
case PlayerState.piercingShooting: | |
if (pierceingShotInput == false) | |
{ | |
state = PlayerState.idle; | |
} | |
break; | |
} | |
} | |
void handleState() | |
{ | |
switch (state) | |
{ | |
case PlayerState.idle: | |
anim.applyRootMotion = false; | |
rigid.drag = 4; | |
onEmpty = true; | |
HandleRotation(); | |
//if (moveAmount > 0 || lookDir != Vector3.zero) { DoChangeState(PlayerState.walking); return; } | |
break; | |
case PlayerState.walking: | |
//combotimer = 0 | |
anim.applyRootMotion = false; | |
rigid.drag = 0; // no drag on movement | |
onEmpty = true; | |
//THIS MIGHT NEED DO BE FOR DASHING AS WELL | |
HandleMove(); | |
HandleRotation(); | |
break; | |
case PlayerState.falling: | |
anim.applyRootMotion = false; | |
rigid.drag = 4; // drag of 4 makes air controls slippery | |
HandleMove(); | |
HandleRotation(); | |
break; | |
case PlayerState.dashing: | |
rigid.drag = 0; | |
HandleRolls(); | |
break; | |
case PlayerState.meleeAttackingStart: | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.7f); | |
foreach (GameObject g in myWeapon.w_hook.damageCollider) | |
{ | |
g.GetComponent<DamageCollider>().damage = lightAttackDamage; | |
} | |
//anim.applyRootMotion = true; //attacks move you forward | |
onEmpty2 = anim.GetBool("onEmpty2"); | |
if (onEmpty2 == true) | |
{ | |
DetectAction(); | |
onEmpty = false; | |
onEmpty2 = false; | |
} | |
HandleMove(); | |
HandleRotationAttack(); | |
break; | |
case PlayerState.meleeAttacking: | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.7f); | |
HandleMove(); | |
HandleRotationAttack(); | |
//anim.applyRootMotion = true; | |
//damage colliders opened on sword | |
break; | |
case PlayerState.meleeAttackingEnd: | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.7f); | |
HandleMove(); | |
HandleRotationAttack(); | |
//anim.applyRootMotion = true; | |
break; | |
case PlayerState.groundPounding: | |
if (_groundPoundCooldownTimer == 0) | |
{ | |
foreach (GameObject g in myWeapon.w_hook.damageCollider) | |
{ | |
g.GetComponent<DamageCollider>().damage = groundSlamAttackDamage; | |
} | |
anim.applyRootMotion = true; //attacks move you forward | |
HandleRotationAttack(); | |
DetectAction(); | |
groundPounded = true; | |
} | |
break; | |
case PlayerState.lightShooting: | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.7f); | |
HandleMove(); | |
HandleRotation(); | |
break; | |
case PlayerState.piercingShooting: | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.7f); | |
HandleMove(); | |
HandleRotation(); | |
break; | |
case PlayerState.stunned: | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.7f); | |
break; | |
} | |
if (state != PlayerState.meleeAttackingStart && state != PlayerState.meleeAttacking && state != PlayerState.meleeAttackingEnd) | |
{ | |
_comboTimer += delta; | |
if (_comboTimer > 0.4) | |
{ | |
actionManager.actionStepIndex = 0; | |
_comboTimer = 0; | |
} | |
} | |
if (groundPounded) | |
{ | |
_groundPoundCooldownTimer += delta; | |
if (_groundPoundCooldownTimer > groundSlamCoolDown) | |
{ | |
_groundPoundCooldownTimer = 0; | |
groundPounded = false; | |
} | |
} | |
//dashing, walking | |
ConvertMoveInput(); // converts move info to local move info for animator | |
HandleMovementAnimations(); | |
if (!teleporting) | |
KeepPlayerOnScreen(true); | |
else KeepPlayerOnScreen(false); | |
} | |
public void FixedTick2(float d) | |
{ | |
delta = d; | |
//convert melee light input to be on mo | |
changeStates(); | |
handleState(); | |
Vector3 vv = new Vector3(this.transform.position.x, startY, this.transform.position.z); | |
this.transform.position = vv; | |
} | |
public void FixedTick(float d) | |
{ | |
delta = d; | |
usingItem = anim.GetBool("interacting"); | |
//if (canMove == false || inAction) | |
// return; | |
DetectAction(); | |
//TODO could change melee animation based on mode light or dark. | |
//inventoryManager.curWeapon.weaponModel.SetActive(!usingItem); | |
if (takeDamage)//stunned | |
{ | |
stunnedTimer += delta; | |
if (stunnedTimer > 0.2) | |
{ | |
takeDamage = false; | |
stunnedTimer = 0; | |
} | |
else | |
{ | |
return; | |
} | |
} | |
if (inAction) | |
{ | |
anim.applyRootMotion = true; | |
_actionDelay += delta; | |
if (_actionDelay > 0.2f) | |
{ | |
inAction = false; | |
_actionDelay = 0; | |
} | |
else | |
{ | |
return; | |
} | |
} | |
onEmpty = anim.GetBool("onEmpty"); | |
if (onEmpty) | |
{ | |
_comboTimer += delta; | |
if (_comboTimer > 0.2) | |
{ | |
actionManager.actionStepIndex = 0; | |
_comboTimer = 0; | |
} | |
} | |
else | |
{ | |
_comboTimer = 0; | |
} | |
//really could set to canmove, but would be confusing. | |
//canMove = anim.GetBool("canMove"); | |
//Debug.Log("getBool"); | |
if (!onEmpty && damageCollidersOpen == false) | |
{ | |
HandleRotationAttack(); | |
} | |
if (!onEmpty && !canMove) // animation is playing | |
{ | |
return; | |
} | |
if (canMove && !onEmpty) // here we are cancling attack anim to let player move faster | |
{ | |
if (moveAmount > 0) | |
{ | |
anim.CrossFade("Empty Override", 0.1f); | |
onEmpty = true; | |
} | |
} | |
//a_hook.rm_multi = 1; | |
a_hook.CloseRoll(); | |
HandleRolls(); | |
anim.applyRootMotion = false; | |
rigid.drag = (moveAmount > 0 || onGround == false) ? 0 : 4; // if we are not moving apply drag to keep char from sliding | |
// Drag is just a measure of how much velocity is lost per tick | |
//Debug.Log(rigid.drag); | |
float targetSpeed = moveSpeed; | |
if (usingItem) | |
{ | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.3f); | |
} | |
if (takeDamage)//character stunned so movemnt slowed | |
{ | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.3f); | |
} | |
if (holdingShoot) | |
{ | |
moveAmount = Mathf.Clamp(moveAmount, 0, 0.7f); | |
//targetSpeed = aimSpeed; | |
//moveAmount = Mathf.Clamp(vertical, 0, 0.5f); | |
//horizontal = Mathf.Clamp(horizontal, 0, 0.5f); | |
} | |
if (onGround) | |
{ | |
rigid.velocity = moveDir * (targetSpeed * moveAmount); | |
anim.speed = MovementAnimationSpeed; | |
} | |
// do integer multiplication first, then multiply by vector which unity casts (more performant) | |
HandleRotation(); | |
ConvertMoveInput(); // converts move info to local move info for animator | |
HandleMovementAnimations(); | |
if (!teleporting) | |
KeepPlayerOnScreen(true); | |
else KeepPlayerOnScreen(false); | |
} | |
void HandleRolls() | |
{ | |
if (onEmpty == false) | |
return; | |
//this code makes you roll and then turn toward roll dir | |
// it commented out for directional dashes | |
//v = (moveAmount > 0.3f) ? 1 : 0; | |
/*h = 0; | |
if (moveDir == Vector3.zero) | |
moveDir = transform.forward; | |
Quaternion targetRot = Quaternion.LookRotation(moveDir); | |
transform.rotation = targetRot; | |
if (Mathf.Abs(v) < 0.3f) | |
v = 0; | |
if (Mathf.Abs(h) < 0.3f) | |
h = 0; | |
*/ | |
onEmpty = false; | |
a_hook.rm_multi = rollSpeed; | |
anim.Play("dash"); | |
a_hook.InitForRoll(); | |
} | |
public void HandleMove() | |
{ | |
float y = rigid.velocity.y; | |
Vector3 velocity = moveDir * (moveSpeed * moveAmount); | |
velocity.y = y; | |
rigid.velocity = velocity; | |
anim.speed = MovementAnimationSpeed; | |
} | |
public void HandleRotation() | |
{ | |
Vector3 targetDir; | |
if (usingMouse) // if using mouse | |
{ | |
//int layer_mask = LayerMask.GetMask("Default","Enemy","Cows"); EXAMPLE | |
int layer_mask = LayerMask.GetMask("Default"); | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
RaycastHit hit; | |
if (Physics.Raycast(ray, out hit, 100, layer_mask)) | |
{ | |
lookPos = hit.point; | |
} | |
targetDir = lookPos - transform.position; | |
targetDir.y = 0; | |
Quaternion tr = Quaternion.LookRotation(targetDir); | |
Quaternion targetRotation = Quaternion.Slerp(transform.rotation, tr, delta * 20); | |
transform.rotation = targetRotation; | |
//transform.LookAt(transform.position + targetDir, Vector3.up); | |
} | |
else if (verticalR != 0 || horizontalR != 0) //if player pressing something on right joystick | |
{ | |
targetDir = lookDir; | |
targetDir.y = 0; | |
//transform.LookAt(transform.position + targetDir, Vector3.up); | |
Quaternion tr = Quaternion.LookRotation(targetDir); | |
Quaternion targetRotation = Quaternion.Slerp(transform.rotation, tr, delta * aimRotateSpeed); | |
transform.rotation = targetRotation; | |
} | |
else | |
{ //default | |
// This makes us rotate to the direction we are walking toward (normal movement) | |
targetDir = moveDir; | |
targetDir.y = 0; | |
if (targetDir == Vector3.zero) | |
targetDir = transform.forward; | |
Quaternion tr = Quaternion.LookRotation(targetDir); | |
Quaternion targetRotation = Quaternion.Slerp(transform.rotation, tr, delta * moveAmount * rotateSpeed); | |
transform.rotation = targetRotation; | |
} | |
} | |
public void HandleRotationAttack() // same as other just different numbers. | |
{ | |
Vector3 targetDir; | |
if (usingMouse) // if using mouse | |
{ | |
int layer_mask = LayerMask.GetMask("Default"); | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
RaycastHit hit; | |
if (Physics.Raycast(ray, out hit, 100, layer_mask)) | |
{ | |
lookPos = hit.point; | |
} | |
targetDir = lookPos - transform.position; | |
targetDir.y = 0; | |
Quaternion tr = Quaternion.LookRotation(targetDir); | |
Quaternion targetRotation = Quaternion.Slerp(transform.rotation, tr, delta * 20); | |
transform.rotation = targetRotation; | |
//transform.LookAt(transform.position + targetDir, Vector3.up); | |
} | |
else if (verticalR != 0 || horizontalR != 0) //if player pressing something on right joystick | |
{ | |
targetDir = lookDir; | |
targetDir.y = 0; | |
//transform.LookAt(transform.position + targetDir, Vector3.up); | |
Quaternion tr = Quaternion.LookRotation(targetDir); | |
Quaternion targetRotation = Quaternion.Slerp(transform.rotation, tr, delta * aimRotateSpeed); | |
transform.rotation = targetRotation; | |
} | |
else | |
{ //default | |
// This makes us rotate to the direction we are walking toward (normal movement) | |
targetDir = moveDir; | |
targetDir.y = 0; | |
if (targetDir == Vector3.zero) | |
targetDir = transform.forward; | |
Quaternion tr = Quaternion.LookRotation(targetDir); | |
Quaternion targetRotation = Quaternion.Slerp(transform.rotation, tr, delta * moveAmount * 20); | |
transform.rotation = targetRotation; | |
} | |
} | |
public void TakeDamage(float d, LightMode lightMode) | |
{ | |
tookDamageFromEnemy = true; | |
//Vector3 pos = other.transform.position; | |
//pos.y = this.transform.position.y - 1; | |
//Debug.Log(ExplosionForce + " " + pos + " " + ExplosionRadius); | |
//rigid.AddExplosionForce(ExplosionForce, pos, ExplosionRadius, yModifiy); | |
//firstRenderer.material.color = Color.white; | |
//secondRenderer.material.color = Color.white; | |
//Invoke("ResetColor", flashTime); | |
if (d == 1000) | |
return; | |
Debug.Log(GameManager.Instance.debugMode); | |
if (!GameManager.Instance.debugMode) | |
GameManager.Instance.currentHealthPoints = GameManager.Instance.currentHealthPoints - (int)d; | |
if (GameManager.Instance.currentHealthPoints <= 0) | |
{ | |
if (!GameManager.Instance.debugMode) | |
GameManager.Instance.ChangeGameState(GameState.Death); | |
//FindObjectOfType<CheckPointManager>().placePlayerOnCheckPoint(GetComponent<Player>()); | |
} | |
if (GetComponent<Player>().lightMode == LightMode.purple) | |
{ | |
AudioManager.Main.PlayPlayerSound(PlayerAudioType.RPlayerHit, gameObject); | |
} else | |
{ | |
AudioManager.Main.PlayPlayerSound(PlayerAudioType.MPlayerHit, gameObject); | |
} | |
if (GetComponent<Player>().lightMode != LightMode.yellow) | |
{ | |
anim.Play("stunned"); | |
myWeapon.w_hook.CloseDamageColliders(); | |
} | |
//played stunned, cant move. lower healthbar | |
} | |
public void DetectLightMelee() | |
{ | |
if (onEmpty == false) | |
return; | |
string targetAnim = null; | |
KE.Action slot = actionManager.lightMeleeAction; | |
if (slot == null) | |
{ | |
Debug.LogWarning("forgot to assign buttons"); | |
return; | |
} | |
if (slot.GetActionStep(ref actionManager.actionStepIndex) == null) | |
return; | |
targetAnim = slot.GetActionStep(ref actionManager.actionStepIndex).GetBranch(slot.input).targetAnim; | |
if (string.IsNullOrEmpty(targetAnim)) | |
return; | |
onEmpty = false; | |
} | |
void DetectAction() | |
{ | |
if (onEmpty == false) | |
return; | |
if (onEmpty2 == false) | |
return; | |
string targetAnim = null; | |
KE.Action slot = actionManager.GetActionSlot(GetComponent<PlayerInput>()); | |
if (slot == null) | |
{ | |
Debug.LogWarning("forgot to assign buttons"); | |
return; | |
} | |
//Debug.LogWarning(slot.GetActionStep(ref actionManager.actionStepIndex)); | |
if (slot.GetActionStep(ref actionManager.actionStepIndex) == null) | |
return; | |
targetAnim = slot.GetActionStep(ref actionManager.actionStepIndex).GetBranch(slot.input).targetAnim; | |
if (groundPoundInput) | |
targetAnim = "oh_attack_10"; | |
if (string.IsNullOrEmpty(targetAnim)) | |
return; | |
onEmpty = false; | |
/* this can go | |
canMove = false; | |
inAction = true; | |
*/ | |
if (targetAnim == "oh_attack_10") // groundslam | |
{ | |
GameManager.Instance.uiParent.darkPlayerCoolDowns[1].GetComponent<CoolDown>().triggerCooldown(groundSlamCoolDown); | |
GroundslamSound(); | |
Invoke("GroundslamShake", 0.5f); | |
} else //light melee | |
{ | |
GameManager.Instance.uiParent.darkPlayerCoolDowns[0].GetComponent<CoolDown>().triggerCooldown(); | |
} | |
anim.Play(targetAnim); | |
GetComponent<KE.PlayerShooting>().checkEnemysHearsShoot(); | |
AudioManager.Main.PlayPlayerSound(PlayerAudioType.MPlayerMain, gameObject); | |
meleeInput = false; | |
} | |
void GroundslamSound() | |
{ | |
AudioManager.Main.PlayPlayerSound(PlayerAudioType.MPlayerHeavy, gameObject); | |
} | |
void GroundslamShake() | |
{ | |
Camera.main.GetComponent<CameraShake>().Shake(0.6f, 0.6f, true); | |
} | |
void ConvertMoveInput() // converts look direction input to play correct animations | |
{ | |
Vector3 localMove = transform.InverseTransformDirection(moveDir); | |
horizontal = localMove.x; | |
moveAmount = localMove.z; | |
} | |
public void Tick(float d) | |
{ | |
delta = Time.deltaTime; | |
onGround = OnGround(); | |
anim.SetBool("onGround", onGround); | |
} | |
void KeepPlayerOnScreen(bool b) | |
{ | |
if (b) | |
{ | |
var pos = Camera.main.WorldToViewportPoint(transform.position); | |
pos.x = Mathf.Clamp(pos.x, 0.05f, 0.95f); | |
pos.y = Mathf.Clamp(pos.y, 0.05f, 0.9f); | |
transform.position = Camera.main.ViewportToWorldPoint(pos); | |
} | |
} | |
void HandleMovementAnimations() | |
{ | |
//if(gameObject.GetComponent<Player>().lightMode == true) | |
anim.SetBool("aiming", false); | |
anim.SetFloat("vertical", moveAmount, 0.3f, delta); | |
anim.SetFloat("horizontal", horizontal); | |
} | |
// Start is called before the first frame update | |
void Start() | |
{ | |
//firstOriginalColor = firstRenderer.material.color; | |
//secondOriginalColor = secondRenderer.material.color; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
if (Input.GetKeyDown(KeyCode.Alpha7)) | |
{ | |
TakeDamage(20, LightMode.neutral); | |
} | |
} | |
void LookAtMouse() | |
{ | |
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
RaycastHit hit; | |
if (Physics.Raycast(ray, out hit, 100)) | |
{ | |
lookPos = hit.point; | |
} | |
Vector3 lookDir = lookPos - transform.position; | |
lookDir.y = 0; | |
transform.LookAt(transform.position + lookDir, Vector3.up); | |
} | |
public bool OnGround() //returns if player is grounded or not | |
{ | |
bool r = false; | |
Vector3 origin = transform.position + (Vector3.up * m_CapsuleHeight / 2);// find center of capsule collider | |
Vector3 dir = -Vector3.up; | |
RaycastHit hit; | |
if (Physics.Raycast(origin, dir, out hit, groundCheckDistance)) // raycast down from capsule collider and see if we hit ground | |
{ | |
r = true; | |
Vector3 targetPosition = hit.point; | |
transform.position = targetPosition; | |
} | |
m_GroundNormal = Vector3.up; | |
return r; | |
} | |
//public void ResetColor() | |
//{ | |
// firstRenderer.material.color = firstOriginalColor; | |
// secondRenderer.material.color = secondOriginalColor; | |
//} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment