壁にぶつかった時でも、壁にぶつかっていない時と同じようなダメージ処理にしたい
解決したいこと
壁にぶつかった時でも、壁にぶつかっていない時と同じようなダメージ処理にしたい
Unityで横スクロールアクションゲームを作っています。大ダメージを喰らったときに壁にぶつかっていない時だと一回バウンドしたのちにダウン状態になりますが、壁にぶつかった時だとバウンドを行わずにそのままダウン状態になります。どの部分を書き換えればこの様な問題が起きなくなりますか。
発生している問題・エラー
または、問題・エラーが起きている画像をここにドラッグアンドドロップ
該当するソースコード
using System.Collections;
using System.Collections.Generic;
using Unity.Burst.CompilerServices;
using UnityEditor.Search;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.EnhancedTouch;
public class PlayerController : MonoBehaviour
{
[Header("Script Connector")]
public static PlayerController instance;
public GameObject BasicVisual;
public GameObject RollingVisual;
public GameObject MakarovaVisual;
public bool BasicMode;
public bool RollingMode;
[Header("Character's Core")]
public CharacterController controller;
public PlayerInput input;
[Header("Flipping")]
public bool isFacingRight;
[Header("Input Actions")]
public InputAction move;
public InputAction aimingMove;
public InputAction jump;
public InputAction attack;
public InputAction dbps;
public InputAction obs;
[Header("Attack Trigger")]
public bool Fist;
public bool Pistol;
public bool Aiming;
[Header("Ability Controller")]
public bool CanSkidAttack;
public bool CanSliding;
public bool CanHipDrop;
public bool CanWallJump;
[Header("Speed Meter")]
public Vector3 velocity;
[Header("Ground Check")]
public bool isGrounded;
[Header("Gravity Controller")]
public float gravityScale = 5;
[Header("Movement")]
public bool fastAirStraff;
public bool AutoRun;
public float maxRunX;
public float maxWalkX;
public float walkAcc;
public float runAcc;
public float skidPower;
public float releaseDeAcc;
public float airStrafeBorder;
public float airStrafeFast;
[Header("Jump")]
public bool isJumping;
public bool isDoubleJumping;
public float jumpForce;
public float jumpTimeCounter;
public float jumpTime;
public float MultipleJump;
public float MaxMultipleJump;
[Header("Crouch")]
public bool DownPressed;
public bool isCrouched = true;
public bool isCrouchGrounded;
[Header("Sliding")]
public bool Sliding;
public float slideAcc;
public float maxSlideSpeed;
public float slidingTimer;
public float slidingTime;
[Header("Running Attack")]
public bool isRunningAttack;
public float RunningAttackTimeCounter;
public float RunningAttackTime;
[Header("Air Attack")]
public bool AirAttack;
[Header("Hip Drop")]
public bool HipDropAction;
public bool isHipDropped;
public bool HipDropReady;
public bool HipDrop;
public bool HipDropCrushed;
public float HipDropBounce = 2;
public float HipDropChargeTimer;
public float HipDropChargeTime;
public float HipDropSpeed;
[Header("Wall Sliding")]
public bool isWallSliding;
public float wallSlidingSpeed;
[Header("Wall Jump")]
public bool wallJumping;
public float wallJumpXspeed;
public float wallJumpYspeed;
[Header("Bullet")]
public bool Fire;
public bool Turbo;
public float FireTimer;
public float FireTime;
[Header("Wall Crushed")]
public bool WallCrushed;
public bool CrushRolling;
public float CrushBound;
[Header("Damage")]
public bool Damaged;
public float knockBackForce = 3;
public float knockBackTimer;
public float knockBackTime;
[Header("Big Damage")]
public bool BigDamaged;
public bool BigDamageCrush;
public bool BigDamageCrushFall;
public bool BigDamageDown;
public float BigDamageBound;
public float MultipleBoundYForce;
public float BigDamageHitXForce;
public float BigDamageHitYForce;
public float DownTimer;
public float downTime;
public bool FirstRecovery;
public bool SecondRecovery;
public float FirstRecoveryTimer;
public float FirstRecoveryTime;
public float SecondRecoveryTimer;
public float SecondRecoveryTime;
void Awake()
{
instance = this;
}
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
input = GetComponent<PlayerInput>();
MultipleJump = MaxMultipleJump;
isDoubleJumping = false;
move = input.actions.FindAction("Move");
aimingMove = input.actions.FindAction("Aiming Move");
jump = input.actions.FindAction("Jump");
attack = input.actions.FindAction("Attack");
dbps = input.actions.FindAction("Down Button Pressed Sliding");
obs = input.actions.FindAction("One Button Sliding");
}
// Update is called once per frame
void Update()
{
InputCheck();
AttackTrigger();
GroundCheck();
CeilingCollision();
if(Damaged == false)
{
knockBackTimer = knockBackTime;
}
if (BigDamaged == true && velocity.y < 0f && isGrounded == true && BigDamageBound == 0f)
{
BigDamageBound = 1f;
}
if (BigDamageBound == 1f && isGrounded == true)
{
BigDamageCrush = true;
}
if (BigDamageCrush == true && velocity.y < 0 && isGrounded == false)
{
BigDamageCrushFall = true;
}
if (BigDamageCrushFall == true && isGrounded == true)
{
BigDamageDown = true;
}
if (BigDamageDown == true)
{
DownTimer -= 1f;
}
if (DownTimer <= 0f)
{
FirstRecovery = true;
}
if(FirstRecovery == true && BigDamaged == true)
{
FirstRecoveryTimer -= 1f;
}
if(FirstRecoveryTimer <= 0f)
{
FirstRecovery = false;
SecondRecovery = true;
}
if (SecondRecovery == true && BigDamaged == true)
{
SecondRecoveryTimer -= 1f;
}
if(SecondRecoveryTimer <= 0f)
{
FirstRecovery = false;
SecondRecovery = false;
BigDamaged = false;
BigDamageCrush = false;
BigDamageCrushFall = false;
FirstRecoveryTimer = FirstRecoveryTime;
SecondRecoveryTimer = SecondRecoveryTime;
BigDamageDown = false;
BigDamageBound = 0f;
DownTimer = downTime;
}
if (BigDamaged == true)
{
Damaged = false;
isDoubleJumping = false;
isHipDropped = false;
isWallSliding = false;
HipDropAction = false;
isHipDropped = false;
BasicMode = true;
RollingMode = false;
HipDropReady = false;
HipDrop = false;
HipDropCrushed = false;
HipDropBounce = 2f;
Sliding = false;
isCrouched = false;
WallCrushed = false;
BasicVisual.SetActive(true);
controller.center = new Vector3(0, 0, 0);
controller.height = 5.94f;
slidingTimer = slidingTime;
}
if(Damaged == true)
{
knockBackTimer -= Time.deltaTime;
isDoubleJumping = false;
isHipDropped = false;
isWallSliding = false;
HipDropAction = false;
isHipDropped = false;
BasicMode = true;
RollingMode = false;
HipDropReady = false;
HipDrop = false;
Sliding = false;
isCrouched = false;
WallCrushed = false;
BasicVisual.SetActive(true);
controller.center = new Vector3(0, 0, 0);
controller.height = 5.94f;
slidingTimer = slidingTime;
}
if(BigDamaged == false)
{
BigDamageBound = 0f;
BigDamageCrush = false;
BigDamageCrushFall = false;
}
if(knockBackTimer <= 0f)
{
Damaged = false;
velocity.x = 0f;
}
if (HipDropReady == false && HipDrop == false)
{
GravityController();
}
if(Damaged == false && BigDamaged == false && BigDamageCrush == false && BigDamageDown == false && FirstRecovery == false && SecondRecovery == false)
{
Jump();
Flipping();
if (Pistol == true)
{
Shoot();
}
if (Fist == true)
{
RunningAttack();
AirAttackController();
}
if (CanSliding == true)
{
SlidingController();
}
if (CanWallJump == true)
{
WallSliding();
WallJump();
}
}
VisualChanger();
}
void FixedUpdate()
{
PositionLock();
if(Damaged == false && BigDamaged == false && BigDamageCrush == false && BigDamageDown == false && FirstRecovery == false && SecondRecovery == false)
{
if (PlayerMeleeAttack.instance.isAttacked == false && isRunningAttack == false && HipDropReady == false && HipDrop == false)
{
Movement();
CrouchController();
}
if (CanSliding == true)
{
SlidingVelocity();
}
if (Fist == true)
{
MeleeAttack();
RunningAttackVelocity();
}
WallCrushMovement();
if (CanHipDrop == true)
{
HipDropController();
}
}
if (BigDamageBound == 1f && isGrounded == true && GroundChecker.instance.groundSlopeAngle == 0)
{
velocity.y = MultipleBoundYForce;
}
if (BigDamageDown == true)
{
velocity.x = 0f;
velocity.y = 0f;
}
}
#region Flipping
void Flipping()
{
if (Left && HipDropReady == false && HipDrop == false && wallJumping == false)
{
isFacingRight = false;
}
if (Right && HipDropReady == false && HipDrop == false && wallJumping == false)
{
isFacingRight = true;
}
}
#endregion
#region Attack Trigger
void AttackTrigger()
{
if(Fist == true)
{
Fist = true;
Pistol = false;
}
if(Pistol == true)
{
Fist = false;
Pistol = true;
}
}
#endregion
#region Position Lock
void PositionLock()
{
Vector3 lockedZpos = transform.position;
lockedZpos.z = 0;
transform.position = lockedZpos;
}
#endregion
#region Visual Changer
void VisualChanger()
{
if (BasicMode == true && Fire == true)
{
PlayerAnimator.instance.sprite.enabled = false;
RollingVisual.SetActive(false);
MakarovaVisual.SetActive(true);
RollingMode = false;
}
if (BasicMode == true && Fire == false)
{
PlayerAnimator.instance.sprite.enabled = true;
RollingVisual.SetActive(false);
MakarovaVisual.SetActive(true);
RollingMode = false;
}
if (RollingMode == true)
{
PlayerAnimator.instance.sprite.enabled = false;
RollingVisual.SetActive(true);
MakarovaVisual.SetActive(false);
BasicMode = false;
}
}
#endregion
#region Gravity Controller
void GravityController()
{
float yStore = velocity.y;
velocity.y = yStore;
velocity.y += Physics.gravity.y * Time.deltaTime * gravityScale;
if(HipDropReady == false && HipDrop == false)
{
controller.Move(velocity * Time.deltaTime);
}
if (HipDropReady == true && HipDrop == true)
{
controller.Move(velocity);
}
}
#endregion
#region Input Check
[HideInInspector]
public bool Right, Left, Down, Up, AimRight, AimLeft, AimDown, AimUp, Sprint;
void InputCheck()
{
Vector2 direction = move.ReadValue<Vector2>();
Vector2 aimingDirection = aimingMove.ReadValue<Vector2>();
Right = direction.x > 0;
Left = direction.x < 0;
Down = direction.y < 0;
Up = direction.y > 0;
AimRight = aimingDirection.x > 0;
AimLeft = aimingDirection.x < 0;
AimDown = aimingDirection.y < 0;
AimUp = aimingDirection.y > 0;
//Sprint = Input.GetButton("Sprint");
}
#endregion
#region Ground Check
void GroundCheck()
{
if(controller.isGrounded == true)
{
isGrounded = true;
MultipleJump = MaxMultipleJump;
isDoubleJumping = false;
isHipDropped = false;
controller.stepOffset = 0.3f;
}else if(controller.isGrounded == false)
{
isGrounded = false;
}
}
#endregion
#region Ceiling Collision
void CeilingCollision()
{
if ((controller.collisionFlags & CollisionFlags.Above) != 0)
{
velocity.y = -3f;
isJumping = false;
jumpTimeCounter = 0f;
controller.stepOffset = 0f;
}
}
#endregion
#region Movement
void Movement()
{
bool moving = false;
bool skidding = false;
#region Right Movement
if (Right && isCrouchGrounded == false)
{
if(isGrounded == false)
{
if(velocity.x >= 0)
{
if(velocity.x >= airStrafeBorder)
{
velocity.x += runAcc;
}
else
{
velocity.x += walkAcc;
}
}else if(velocity.x < 0)
{
if(-velocity.x >= airStrafeBorder)
{
velocity.x += runAcc;
}
else
{
if (fastAirStraff)
{
velocity.x += releaseDeAcc;
}
velocity.x += walkAcc;
}
}
}
else
{
moving = true;
if(velocity.x >= 0)
{
if (Sprint || AutoRun)
{
velocity.x += runAcc;
}
else velocity.x += walkAcc;
}else if(velocity.x < 0)
{
velocity.x += skidPower;
skidding = true;
}
}
}
#endregion
#region Left Movement
if (Left && isCrouchGrounded == false)
{
if (isGrounded == false)
{
if(velocity.x <= 0)
{
if(-velocity.x >= airStrafeBorder)
{
velocity.x -= runAcc;
}
else
{
velocity.x -= walkAcc;
}
}else if(velocity.x > 0)
{
if(velocity.x >= airStrafeBorder)
{
velocity.x -= runAcc;
}
else
{
if (fastAirStraff)
{
velocity.x -= releaseDeAcc;
}
velocity.x -= walkAcc;
}
}
}
else
{
moving = true;
if(velocity.x <= 0)
{
if (Sprint)
{
velocity.x -= runAcc;
}
else velocity.x -= walkAcc;
}else if(velocity.x > 0)
{
velocity.x -= skidPower;
skidding = true;
}
}
}
#endregion
#region Basic Movement
if (!moving && isGrounded)
{
if(velocity.x > 0)
{
velocity.x -= releaseDeAcc;
if (velocity.x < 0) velocity.x = 0;
}
else
{
velocity.x += releaseDeAcc;
if (velocity.x > 0) velocity.x = 0;
}
}
float maxSpeed = Sprint || AutoRun ? maxRunX : maxWalkX;
if(velocity.x > maxSpeed && Sliding == false)
{
velocity.x = maxSpeed;
}else if(velocity.x < -maxSpeed && Sliding == false)
{
velocity.x = -maxSpeed;
}
#endregion
if (velocity.x > maxSlideSpeed && Sliding == true && PlayerMeleeAttack.instance.isAttacked == false)
{
velocity.x = maxSlideSpeed;
}
else if (velocity.x < -maxSlideSpeed && Sliding == true && PlayerMeleeAttack.instance.isAttacked == false)
{
velocity.x = -maxSlideSpeed;
}
}
#endregion
#region Jump
void Jump()
{
if (CanSliding == false)
{
if (jump.WasPressedThisFrame() && MultipleJump > 0 && PlayerMeleeAttack.instance.isAttacked == false)
{
isJumping = true;
MultipleJump -= 1f;
velocity.y = jumpForce;
jumpTimeCounter = jumpTime;
}
}
if (CanSliding == true)
{
if (jump.WasPressedThisFrame() && MultipleJump > 0 && isCrouchGrounded == false && PlayerMeleeAttack.instance.isAttacked == false)
{
isJumping = true;
MultipleJump -= 1f;
velocity.y = jumpForce;
jumpTimeCounter = jumpTime;
}
}
if (jump.IsPressed() && isJumping == true)
{
if(jumpTimeCounter > 0)
{
velocity.y = jumpForce;
jumpTimeCounter -= Time.deltaTime;
}
else
{
isJumping = false;
}
}
if (jump.WasReleasedThisFrame())
{
isJumping = false;
}
if(isGrounded == false && jump.WasPressedThisFrame())
{
BasicMode = false;
RollingMode = true;
isDoubleJumping = true;
isHipDropped = true;
AirAttack = false;
}
if(isDoubleJumping == true)
{
BasicMode = false;
RollingMode = true;
isDoubleJumping = true;
isHipDropped = true;
}
if (isDoubleJumping == false)
{
BasicMode = true;
RollingMode = false;
isDoubleJumping = false;
isHipDropped = false;
}
if (isGrounded == true)
{
MultipleJump = MaxMultipleJump;
isDoubleJumping = false;
isHipDropped = false;
}
}
#endregion
#region Crouch
void CrouchController()
{
if (Down)
{
DownPressed = true;
}
else
{
DownPressed = false;
}
if (isCrouched == true || Sliding == true)
{
controller.center = new Vector3(0, -1.23f, 0);
controller.height = 3.48f;
}
else
{
controller.center = new Vector3(0, 0, 0);
controller.height = 5.94f;
}
if (DownPressed == true && isGrounded == true && Aiming == false)
{
isCrouched = true;
if (velocity.x > 0 && velocity.x != 0)
{
velocity.x -= skidPower;
if (velocity.x < 0.5f)
{
velocity.x = 0f;
}
}
if (velocity.x < 0 && velocity.x != 0)
{
velocity.x += skidPower;
if (velocity.x > 0.5f)
{
velocity.x = 0f;
}
}
}
if (DownPressed == true && isGrounded == true && Aiming == true && Fire == false)
{
isCrouched = true;
if (velocity.x > 0 && velocity.x != 0)
{
velocity.x -= skidPower;
if (velocity.x < 0.5f)
{
velocity.x = 0f;
}
}
if (velocity.x < 0 && velocity.x != 0)
{
velocity.x += skidPower;
if (velocity.x > 0.5f)
{
velocity.x = 0f;
}
}
}
if (DownPressed == false && controller.isGrounded == true)
{
isCrouched = false;
}
if (isCrouched == true && controller.isGrounded == true)
{
isCrouchGrounded = true;
}
else if (isCrouched == false || isCrouched == true && controller.isGrounded == false)
{
isCrouchGrounded = false;
}
}
#endregion
#region Sliding Controller
void SlidingController()
{
if (DownPressed)
{
if (dbps.WasPressedThisFrame() && isCrouchGrounded)
{
Sliding = true;
HipDropBounce = 0f;
controller.Move(velocity * Time.deltaTime);
}
}
if (obs.WasPressedThisFrame() && isGrounded)
{
Sliding = true;
HipDropBounce = 0f;
controller.Move(velocity * Time.deltaTime);
}
if (Sliding == false)
{
slidingTimer = slidingTime;
}
}
void SlidingVelocity()
{
if (Sliding == true && slidingTimer > 0)
{
slidingTimer -= Time.deltaTime;
if (PlayerAnimator.instance.isFacingRight == true)
{
velocity.x += slideAcc;
}
if (PlayerAnimator.instance.isFacingRight == false)
{
velocity.x -= slideAcc;
}
}
if (slidingTimer < 0)
{
if (PlayerAnimator.instance.isFacingRight == true)
{
velocity.x -= slideAcc;
if (velocity.x <= 0)
{
velocity.x = 0f;
}
}
if (PlayerAnimator.instance.isFacingRight == false)
{
velocity.x += slideAcc;
if (velocity.x >= 0)
{
velocity.x = 0f;
}
}
}
if (velocity.x == 0f)
{
Sliding = false;
slidingTimer = slidingTime;
}
if(Sliding == true && isGrounded == false)
{
isDoubleJumping = true;
isHipDropped = true;
Sliding = false;
isCrouched = false;
if (PlayerAnimator.instance.isFacingRight == true)
{
velocity.x = maxSlideSpeed;
}
if (PlayerAnimator.instance.isFacingRight == false)
{
velocity.x = -maxSlideSpeed;
}
}
else if(isGrounded == true)
{
BasicMode = true;
RollingMode = false;
if (jump.WasPressedThisFrame())
{
BasicMode = true;
RollingMode = false;
}
}
}
#endregion
#region Melee Attack
void MeleeAttack()
{
if (PlayerMeleeAttack.instance.isAttacked == true && isHipDropped == false)
{
if (PlayerAnimator.instance.isFacingRight == true)
{
velocity.x = 3f;
}
else
{
velocity.x = -3f;
}
}
}
#endregion
#region Running Attack
void RunningAttack()
{
if (PlayerAnimator.instance.Idle || PlayerAnimator.instance.Walk || PlayerAnimator.instance.Run || PlayerAnimator.instance.Jump || PlayerAnimator.instance.Fall || PlayerAnimator.instance.Skid || PlayerAnimator.instance.Crouch)
{
RunningAttackTimeCounter = RunningAttackTime;
}
if (Right == true && attack.WasPressedThisFrame() && velocity.x > 10 && PlayerController.instance.isFacingRight == true && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false || Left == true && attack.WasPressedThisFrame() && PlayerController.instance.velocity.x < -10 && PlayerAnimator.instance.isFacingRight == false && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false)
{
isRunningAttack = true;
}
if (Right == true && attack.IsPressed() && velocity.x > 10 && PlayerController.instance.isFacingRight == true && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false || Left == true && attack.IsPressed() && PlayerController.instance.velocity.x < -10 && PlayerAnimator.instance.isFacingRight == false && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false)
{
isRunningAttack = true;
}
if (Left == true && attack.WasPressedThisFrame() && velocity.x > 10 && PlayerController.instance.isFacingRight == false && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false || Right == true && attack.WasPressedThisFrame() && PlayerController.instance.velocity.x < -10 && PlayerAnimator.instance.isFacingRight == true && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false)
{
isRunningAttack = true;
}
if (Left == true && attack.IsPressed() && velocity.x > 10 && PlayerController.instance.isFacingRight == false && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false || Right == true && attack.IsPressed() && PlayerController.instance.velocity.x < -10 && PlayerAnimator.instance.isFacingRight == true && isGrounded == true && isCrouched == false && Sliding == false && isHipDropped == false)
{
isRunningAttack = true;
}
if (isRunningAttack == true)
{
if (RunningAttackTimeCounter > 0)
{
RunningAttackTimeCounter -= Time.deltaTime;
}
else
{
isRunningAttack = false;
}
}
}
void RunningAttackVelocity()
{
if(isRunningAttack == true && isHipDropped == false)
{
if (PlayerAnimator.instance.isFacingRight == true)
{
velocity.x = maxRunX;
}
if (PlayerAnimator.instance.isFacingRight == false)
{
velocity.x = -maxRunX;
}
}
}
#endregion
#region Air Attack Controller
void AirAttackController()
{
if (attack.WasPressedThisFrame() && isGrounded == false && isCrouched == false && HipDropAction == false && HipDropCrushed == false && isWallSliding == false)
{
AirAttack = true;
isDoubleJumping = false;
isHipDropped = false;
}
if (isGrounded == true && AirAttack == true)
{
AirAttack = false;
}
}
#endregion
#region Shoot
void Shoot()
{
if(Turbo == false)
{
if (Sliding == false || RollingMode == false || HipDropReady == false)
{
if (attack.WasPressedThisFrame() && Pistol == true && isCrouched == false && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
if (attack.WasPressedThisFrame() && Pistol == true && isCrouched == true && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
}
if (HipDropAction == false && isDoubleJumping == true && isHipDropped == true)
{
if (attack.WasPressedThisFrame() && Pistol == true && isCrouched == false && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
if (attack.WasPressedThisFrame() && Pistol == true && isCrouched == true && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
}
}
if(Turbo == true)
{
if (Sliding == false || RollingMode == false || HipDropReady == false)
{
if (attack.IsPressed() && Pistol == true && isCrouched == false && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
if (attack.IsPressed() && Pistol == true && isCrouched == true && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
}
if (HipDropAction == false && isDoubleJumping == true && isHipDropped == true)
{
if (attack.IsPressed() && Pistol == true && isCrouched == false && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
if (attack.IsPressed() && Pistol == true && isCrouched == true && Sliding == false && HipDropAction == false && HipDropCrushed == false)
{
Fire = true;
PlayerAnimator.instance.sprite.enabled = false;
FireTimer = FireTime;
}
}
}
if (Fire == true && HipDropReady == false && HipDrop == false)
{
FireTimer -= 0.01f;
PlayerShootingVisual.instance.sprite.enabled = true;
}
if (FireTimer <= 0 || Sliding == true || CrushRolling == true)
{
Fire = false;
}
if (Fire == false)
{
PlayerShootingVisual.instance.sprite.enabled = false;
PlayerAnimator.instance.sprite.enabled = true;
}
if(RollingMode == true && Fire == true)
{
RollingMode = false;
BasicMode = true;
isDoubleJumping = false;
}
}
#endregion
#region Wall Crush Movement
void WallCrushMovement()
{
if (WallCrushed == true)
{
Sliding = false;
isCrouched = false;
BasicMode = false;
RollingMode = true;
CrushRolling = true;
HipDropReady = false;
HipDrop = false;
//isHipDropped = false;
slidingTimer = slidingTime;
if (PlayerAnimator.instance.isFacingRight == true)
{
velocity.x = -10f;
velocity.y = 20f;
}
if (PlayerAnimator.instance.isFacingRight == false)
{
velocity.x = 10f;
velocity.y = 20f;
}
WallCrushed = false;
}
if(CrushRolling == true)
{
BasicVisual.SetActive(false);
//BasicMode = false;
RollingMode = true;
isDoubleJumping = true;
isHipDropped = false;
}
if(CrushRolling == true && isGrounded == true)
{
CrushBound += 1;
}
if(CrushBound >= 2)
{
if (jump.WasPressedThisFrame())
{
CrushRolling = false;
CrushBound = 0;
}
BasicVisual.SetActive(true);
CrushRolling = false;
CrushBound = 0;
}
}
#endregion
#region Hip Drop
void HipDropController()
{
if(isGrounded == false || Sliding == true)
{
HipDropBounce = 0;
}
if(CanSliding == true && isWallSliding == false)
{
if (Down && isGrounded == false && isCrouched == false && Sliding == false && CrushRolling == false && WallCrushed == false && HipDropCrushed == false && AirAttack == false)
{
HipDropAction = true;
isHipDropped = true;
isDoubleJumping = true;
HipDropChargeTimer = HipDropChargeTime;
velocity.x = 0;
velocity.y = 0;
HipDropBounce = 0;
HipDropReady = true;
HipDrop = false;
wallJumping = false;
BasicMode = false;
RollingMode = true;
isRunningAttack = false;
AirAttack = false;
Fire = false;
}
if (HipDropReady == true)
{
HipDropChargeTimer -= Time.deltaTime;
}
if (HipDropChargeTimer < 0 && Sliding == false && HipDropAction == true && CrushRolling == false)
{
HipDrop = true;
BasicMode = true;
RollingMode = false;
isDoubleJumping = false;
Fire = false;
velocity.y = -HipDropSpeed;
controller.Move(velocity);
}
if (HipDrop == true && isGrounded == true && HipDropBounce < 2f)
{
HipDropReady = false;
HipDrop = false;
isDoubleJumping = true;
velocity.y = 30f;
Fire = false;
HipDropChargeTimer = HipDropChargeTime;
controller.Move(velocity * Time.deltaTime);
}
if (isGrounded == true && Sliding == false)
{
HipDropBounce += 1f;
}
if (HipDropBounce == 1f)
{
HipDropAction = false;
HipDropCrushed = true;
isDoubleJumping = true;
BasicMode = false;
RollingMode = true;
}
if (HipDropBounce > 2f)
{
HipDropCrushed = false;
isDoubleJumping = false;
isHipDropped = false;
BasicMode = true;
RollingMode = false;
}
}
if (CanSliding == false && isWallSliding == false)
{
if (Down && isGrounded == false && isCrouched == false && CrushRolling == false && WallCrushed == false && HipDropCrushed == false && isHipDropped == false && AirAttack == false)
{
isHipDropped = true;
HipDropChargeTimer = HipDropChargeTime;
velocity.x = 0;
velocity.y = 0;
HipDropBounce = 0;
HipDropReady = true;
HipDrop = false;
BasicMode = false;
RollingMode = true;
isRunningAttack = false;
AirAttack = false;
Fire = false;
}
if (HipDropReady == true)
{
HipDropChargeTimer -= Time.deltaTime;
}
if (HipDropChargeTimer < 0)
{
HipDrop = true;
BasicMode = true;
RollingMode = false;
velocity.y = -HipDropSpeed;
controller.Move(velocity);
}
if (HipDrop == true && isGrounded == true && HipDropBounce < 2f)
{
HipDropReady = false;
HipDrop = false;
velocity.y = 30f;
HipDropChargeTimer = HipDropChargeTime;
controller.Move(velocity * Time.deltaTime);
}
if (isGrounded == true && isHipDropped == true)
{
HipDropBounce += 1f;
}
if (HipDropBounce == 1f)
{
HipDropCrushed = true;
BasicMode = false;
RollingMode = true;
}
if (HipDropBounce == 2f)
{
HipDropCrushed = false;
isHipDropped = false;
BasicMode = true;
RollingMode = false;
}
}
}
#endregion
#region Wall Jump Controller
#region Wall Sliding
void WallSliding()
{
if(PlayerLeftWallChecker.instance.LeftWallDetected == true && isWallSliding == true)
{
isFacingRight = true;
velocity.y = wallSlidingSpeed;
}
if (PlayerRightWallChecker.instance.RightWallDetected == true && isWallSliding == true)
{
isFacingRight = false;
velocity.y = wallSlidingSpeed;
}
if (PlayerLeftWallChecker.instance.LeftWallDetected == true && isGrounded == false && Right)
{
isWallSliding = false;
}
if (PlayerRightWallChecker.instance.RightWallDetected == true && isGrounded == false && Left)
{
isWallSliding = false;
}
if (PlayerLeftWallChecker.instance.LeftWallDetected == true && isGrounded == false && Left == false)
{
isWallSliding = false;
}
if (PlayerRightWallChecker.instance.RightWallDetected == true && isGrounded == false && Right == false)
{
isWallSliding = false;
}
if (isGrounded == true)
{
isWallSliding = false;
}
}
#endregion
#region Wall Jump
void WallJump()
{
if(PlayerRightWallChecker.instance.RightWallDetected == true && isWallSliding == true && HipDropAction == false && jump.WasPressedThisFrame())
{
isWallSliding = false;
wallJumping = true;
isFacingRight = false;
MultipleJump = MaxMultipleJump;
isDoubleJumping = false;
isHipDropped = false;
velocity.x = -wallJumpXspeed;
velocity.y = wallJumpYspeed;
}
if(PlayerLeftWallChecker.instance.LeftWallDetected == true && isWallSliding == true && HipDropAction == false && jump.WasPressedThisFrame())
{
isWallSliding = false;
wallJumping = true;
isFacingRight = true;
MultipleJump = MaxMultipleJump;
isDoubleJumping = false;
isHipDropped = false;
velocity.x = wallJumpXspeed;
velocity.y = wallJumpYspeed;
}
if(wallJumping == true && velocity.y < 0)
{
wallJumping = false;
}
}
#endregion
#endregion
void OnControllerColliderHit(ControllerColliderHit hit)
{
#region Wall Collider
if (hit.gameObject.tag == "Wall")
{
if (isGrounded == true)
{
velocity.y = -2f;
}
if ((controller.collisionFlags & CollisionFlags.Sides) != 0)
{
velocity.x = 0f;
if (Sliding == true)
{
WallCrushed = true;
}
if (Right)
{
velocity.x = 0.01f;
}
if (Left)
{
velocity.x = -0.01f;
}
if (CanWallJump == true)
{
if (PlayerLeftWallChecker.instance.LeftWallDetected == true && isGrounded == false && Left && AirAttack == false && CrushRolling == false && WallCrushed == false && HipDropCrushed == false && HipDropAction == false && AirAttack == false && BigDamaged == false)
{
velocity.x = -5f;
if(velocity.y < 0f)
{
isWallSliding = true;
isHipDropped = false;
MultipleJump = MaxMultipleJump;
isDoubleJumping = false;
}
}
if (PlayerRightWallChecker.instance.RightWallDetected == true && isGrounded == false && Right && AirAttack == false && CrushRolling == false && WallCrushed == false && HipDropCrushed == false && HipDropAction == false && AirAttack == false && BigDamaged == false)
{
velocity.x = 5f;
if (velocity.y < 0f)
{
isWallSliding = true;
isHipDropped = false;
MultipleJump = MaxMultipleJump;
isDoubleJumping = false;
}
}
}
}
if (controller.collisionFlags == CollisionFlags.Sides)
{
velocity.x = 0f;
if (Right)
{
velocity.x = 0.01f;
}
if (Left)
{
velocity.x = -0.01f;
}
if (CanWallJump == true)
{
if (PlayerLeftWallChecker.instance.LeftWallDetected == true && isGrounded == false && Left && AirAttack == false && CrushRolling == false && WallCrushed == false && HipDropCrushed == false && isHipDropped == false && AirAttack == false && BigDamaged == false)
{
velocity.x = -5f;
if (velocity.y < 0f)
{
isWallSliding = true;
MultipleJump = MaxMultipleJump;
}
}
if (PlayerRightWallChecker.instance.RightWallDetected == true && isGrounded == false && Right && AirAttack == false && CrushRolling == false && WallCrushed == false && HipDropCrushed == false && isHipDropped == false && AirAttack == false && BigDamaged == false)
{
velocity.x = 5f;
if (velocity.y < 0f)
{
isWallSliding = true;
MultipleJump = MaxMultipleJump;
}
}
}
}
}
#endregion
#region Slope Collider
if (hit.gameObject.tag == "Slope")
{
velocity.y = -150f;
}
#endregion
if (hit.gameObject.tag == "Hill")
{
if (GroundChecker.instance.groundSlopeAngle == 0 || GroundChecker.instance.groundSlopeAngle == 90 || GroundChecker.instance.groundSlopeAngle == 180 || GroundChecker.instance.groundSlopeAngle == 270)
{
velocity.y = -2f;
}
else if (GroundChecker.instance.groundSlopeAngle != 0 || GroundChecker.instance.groundSlopeAngle != 0 && GroundChecker.instance.groundSlopeAngle != 90 || GroundChecker.instance.groundSlopeAngle != 0 && GroundChecker.instance.groundSlopeAngle != 180 || GroundChecker.instance.groundSlopeAngle != 0 && GroundChecker.instance.groundSlopeAngle != 270)
{
velocity.y = -150f;
}
}
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Enemy Attack")
{
if(isGrounded == true && BigDamaged == false)
{
Damaged = true;
Vector3 distination = (transform.position - other.transform.position).normalized;
velocity.x = distination.x * knockBackForce;
knockBackTimer = knockBackTime;
}
if (isGrounded == false && BigDamaged == false)
{
BigDamaged = true;
Vector3 distination = (transform.position - other.transform.position).normalized;
velocity.x = distination.x * BigDamageHitXForce;
velocity.y = BigDamageHitYForce;
knockBackTimer = knockBackTime;
DownTimer = downTime;
FirstRecoveryTimer = FirstRecoveryTime;
SecondRecoveryTimer = SecondRecoveryTime;
}
}
if(other.gameObject.tag == "Enemy Large Attack")
{
if (BigDamaged == false)
{
BigDamaged = true;
Vector3 distination = (transform.position - other.transform.position).normalized;
velocity.x = distination.x * BigDamageHitXForce;
velocity.y = BigDamageHitYForce;
knockBackTimer = knockBackTime;
DownTimer = downTime;
FirstRecoveryTimer = FirstRecoveryTime;
SecondRecoveryTimer = SecondRecoveryTime;
}
}
}
void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Enemy Attack")
{
if (isGrounded == true && BigDamaged == false)
{
Damaged = true;
Vector3 distination = (transform.position - other.transform.position).normalized;
velocity.x = distination.x * knockBackForce;
knockBackTimer = knockBackTime;
}
if (isGrounded == false && BigDamaged == false)
{
BigDamaged = true;
Vector3 distination = (transform.position - other.transform.position).normalized;
velocity.x = distination.x * BigDamageHitXForce;
velocity.y = BigDamageHitYForce;
knockBackTimer = knockBackTime;
DownTimer = downTime;
FirstRecoveryTimer = FirstRecoveryTime;
SecondRecoveryTimer = SecondRecoveryTime;
}
}
if (other.gameObject.tag == "Enemy Large Attack")
{
if (BigDamaged == false)
{
BigDamaged = true;
Vector3 distination = (transform.position - other.transform.position).normalized;
velocity.x = distination.x * BigDamageHitXForce;
velocity.y = BigDamageHitYForce;
knockBackTimer = knockBackTime;
DownTimer = downTime;
FirstRecoveryTimer = FirstRecoveryTime;
SecondRecoveryTimer = SecondRecoveryTime;
}
}
}
}
自分で試したこと
if(BigDamaged == true)の部分にBigDamageCrush = falseやBigDamageCrushFall = false等の値を入れてもダメでした。
0