void MoveToPlayer(Vector3 A, Vector3 B, float _speed, bool isDashing = false) { Vector3 direction = (B - A).normalized; //gets direction direction.y = 0; //makes the AI not fly up by setting U direction to 0 Quaternion endRot = Quaternion.LookRotation(direction); //makes a quaternion for that look dir if (!isDashing) //if the beetle is NOT dashing and is just walking { if (DistanceBetween(A, B) < attackRange) //do something when the player is within attacking range { BeetleLogic = BossStates.ATTACK; //change states to attack gameTime = 0; } transform.rotation = endRot; //rotate the beetle to face the dir Vector3 offSet = transform.rotation.eulerAngles; offSet.y -= 90; transform.eulerAngles = offSet; transform.position += transform.right * Time.deltaTime * _speed; //moves the beetleforward } if (isDashing) //if however, the beetle IS dashing { transform.rotation = endRot; //set the rotation to face the position Vector3 offSet = transform.rotation.eulerAngles; offSet.y -= 90; transform.eulerAngles = offSet; transform.position += transform.right * Time.deltaTime * _speed; //move it forward if (DistanceBetween(A, B) < 2) //if the beetle reaches near it's destination (where player last was_ { DashLogic = DashStates.DASHEND; //change state to end the dash gameTime = 0; } } }
public void Dash(Rigidbody2D rb2d) { if (dashState == DashStates.DASHING) { rb2d.AddForce(new Vector2(direction * DashForce, 0f)); dashState = DashStates.BLOCKED; } }
void ChangeAttackState(float timeBeforeStateChange, DashStates nextState) { if (attackTime > timeBeforeStateChange) { DashLogic = nextState; attackTime = 0; } }
void Start() { rb = GetComponent <Rigidbody2D>(); anim = GetComponent <Animator>(); dashstate = DashStates.COOLDOWN; canMove = true; isAttacking = false; }
public void CaptureDash() { if (dashState == DashStates.ALLOWED) { if (Input.GetKeyDown(rightKey)) { prevPress = rightKey; dashState = DashStates.WAITING_INPUT; } else if (Input.GetKeyDown(leftKey)) { prevPress = leftKey; dashState = DashStates.WAITING_INPUT; } } else if (dashState == DashStates.WAITING_INPUT) { if (waitInputTimer.Count()) { dashState = DashStates.ALLOWED; } else if (Input.GetKeyDown(rightKey) && prevPress == rightKey) { dashState = DashStates.DASHING; direction = 1f; } else if (Input.GetKeyDown(leftKey) && prevPress == leftKey) { dashState = DashStates.DASHING; direction = -1f; } else if (Input.GetKeyDown(rightKey) && prevPress == leftKey) { dashState = DashStates.ALLOWED; } else if (Input.GetKeyDown(leftKey) && prevPress == rightKey) { dashState = DashStates.ALLOWED; } } else if (dashState == DashStates.BLOCKED) { if (blockTimer.Count()) { dashState = DashStates.ALLOWED; } } }
public static void SetEnabled(this DashStates state, bool enable) { switch (state) { case DashStates.DreamTunnelDash: DreamTunnelDash.HasDreamTunnelDash = enable; break; case DashStates.SeekerDash: SeekerDash.HasSeekerDash = enable; break; default: break; } }
void ChangeAttackState(float timeBeforeStateChange,DashStates nextState) { if(attackTime > timeBeforeStateChange) { DashLogic = nextState; attackTime = 0; } }
void MoveToPlayer(Vector3 A, Vector3 B,float _speed, bool isDashing = false) { Vector3 direction = (B - A).normalized; //gets direction direction.y = 0; //makes the AI not fly up by setting U direction to 0 Quaternion endRot = Quaternion.LookRotation(direction); //makes a quaternion for that look dir if(!isDashing) //if the beetle is NOT dashing and is just walking { if (DistanceBetween(A, B) < attackRange) //do something when the player is within attacking range { BeetleLogic = BossStates.ATTACK; //change states to attack gameTime = 0; } transform.rotation = endRot; //rotate the beetle to face the dir Vector3 offSet = transform.rotation.eulerAngles; offSet.y -= 90; transform.eulerAngles = offSet; transform.position += transform.right * Time.deltaTime * _speed; //moves the beetleforward } if(isDashing) //if however, the beetle IS dashing { transform.rotation = endRot; //set the rotation to face the position Vector3 offSet = transform.rotation.eulerAngles; offSet.y -= 90; transform.eulerAngles = offSet; transform.position += transform.right * Time.deltaTime * _speed; //move it forward if (DistanceBetween(A,B)< 2) //if the beetle reaches near it's destination (where player last was_ { DashLogic = DashStates.DASHEND; //change state to end the dash gameTime = 0; } } }
void AttackStateMachine() { BossAnim.SetBool("bIsAttacking", true); switch (AttackLogic) { case AttackStates.AIMING: _neptoScript.range = 20; BossAnim.SetInteger("iAttack", 0); //sets animator to this anim //aiming logic goes here _neptoScript.beetleControl = false; //gives control back to nepto if(hasDeflected) //if player deflected { _neptoScript.range = 5; BossAnim.SetBool("bHasDeflected", true); ChangeState(0f, BossStates.STUNNED); //change state to stunned _neptoScript.beetleControl = true; //gives control back to beetle, disabling the nepto _neptoScript.shootCount = 0; //resets the shot count back to zero BossAnim.SetBool("bIsAttacking", false); //stops attacking animation from playing } if(_neptoScript.shootCount == 4) //if the nepto has shot thrice, regardless of whether you deflected or not { _neptoScript.range = 5; BossAnim.SetBool("bIsAttacking", false); //stops attacking animation from playing _neptoScript.beetleControl = true;//gives control back to the beetle first ChangeState(3f, BossStates.IDLE); //go back to idle after 2 seconds (to allow player time to deflect } break; case AttackStates.DASH: BossAnim.SetInteger("iAttack", 1); //AI deshing goes here attackTime += Time.deltaTime; switch (DashLogic) { case DashStates.CHARGEUP: MoveToPlayer(transform.position, player.position, 0); //makes the beetle only face gulnaz if(attackTime > 3f) { BossAnim.SetTrigger("tCharge"); lastPos = player.position; attackTime = 0; DashLogic = DashStates.DASH; } break; case DashStates.DASH: MoveToPlayer(transform.position, lastPos, 5,true); break; case DashStates.DASHEND: BossAnim.SetTrigger("tDashEnd"); BossAnim.SetBool("bIsAttacking", false); BeetleLogic = BossStates.IDLE; gameTime = 0; DashLogic = DashStates.CHARGEUP; attackTime = 0; break; } break; } }
void AttackStateMachine() { BossAnim.SetBool("bIsAttacking", true); switch (AttackLogic) { case AttackStates.AIMING: _neptoScript.range = 20; BossAnim.SetInteger("iAttack", 0); //sets animator to this anim //aiming logic goes here _neptoScript.beetleControl = false; //gives control back to nepto if (hasDeflected) //if player deflected { _neptoScript.range = 5; BossAnim.SetBool("bHasDeflected", true); ChangeState(0f, BossStates.STUNNED); //change state to stunned _neptoScript.beetleControl = true; //gives control back to beetle, disabling the nepto _neptoScript.shootCount = 0; //resets the shot count back to zero BossAnim.SetBool("bIsAttacking", false); //stops attacking animation from playing } if (_neptoScript.shootCount == 4) //if the nepto has shot thrice, regardless of whether you deflected or not { _neptoScript.range = 5; BossAnim.SetBool("bIsAttacking", false); //stops attacking animation from playing _neptoScript.beetleControl = true; //gives control back to the beetle first ChangeState(3f, BossStates.IDLE); //go back to idle after 2 seconds (to allow player time to deflect } break; case AttackStates.DASH: BossAnim.SetInteger("iAttack", 1); //AI deshing goes here attackTime += Time.deltaTime; switch (DashLogic) { case DashStates.CHARGEUP: MoveToPlayer(transform.position, player.position, 0); //makes the beetle only face gulnaz if (attackTime > 3f) { BossAnim.SetTrigger("tCharge"); lastPos = player.position; attackTime = 0; DashLogic = DashStates.DASH; } break; case DashStates.DASH: MoveToPlayer(transform.position, lastPos, 5, true); break; case DashStates.DASHEND: BossAnim.SetTrigger("tDashEnd"); BossAnim.SetBool("bIsAttacking", false); BeetleLogic = BossStates.IDLE; gameTime = 0; DashLogic = DashStates.CHARGEUP; attackTime = 0; break; } break; } }
protected DashStateTrigger(EntityData data, Vector2 offset) : base(data, offset) { Mode = data.Enum("mode", Modes.Trigger); DashState = data.Enum("dashState", DashStates.DreamTunnelDash); }
void Dash() { if (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)) { direction = Directions.LEFT; } if (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)) { direction = Directions.RIGHT; } if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.UpArrow)) { direction = Directions.UP; } if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow)) { direction = Directions.DOWN; } switch (dashstate) { case DashStates.READY: if (Input.GetKeyDown(KeyCode.Space)) { dashstate = DashStates.DASH; } break; case DashStates.DASH: canMove = false; timeOfDash -= Time.deltaTime; if (timeOfDash <= 0) { canMove = true; dashstate = DashStates.COOLDOWN; } else { if (direction == Directions.UP) { transform.Translate(Vector2.up * Dash_speed * Time.deltaTime); } else if (direction == Directions.DOWN) { transform.Translate(Vector2.down * Dash_speed * Time.deltaTime); } else if (direction == Directions.LEFT) { transform.Translate(Vector2.left * Dash_speed * Time.deltaTime); } else { transform.Translate(Vector2.right * Dash_speed * Time.deltaTime); } } break; case DashStates.COOLDOWN: timeOfDash += Time.deltaTime; if (timeOfDash >= 0.8f) { timeOfDash = 0.8f; dashstate = DashStates.READY; } break; } }