Forum begins after the advertisement:
[Part 4] Cast and Heal problem
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 4] Cast and Heal problem
- This topic has 26 replies, 3 voices, and was last updated 1 month, 3 weeks ago by pepecry.
-
AuthorPosts
-
September 27, 2024 at 1:52 pm #15931::
Ah alright, after taking another look and your confirmation on holding the button.
The reason you’re still firing the DarkBullet spell despite you not being supposed to by code. I’ve found that your
castOrhealTimer
isn’t actually changing ingetInput()
. due to the line being slightly incorrect.Just add a
+
incastOrhealTimer = Time.deltaTime
void getInput() { xAxis = Input.GetAxisRaw("Horizontal"); yAxis = Input.GetAxisRaw("Vertical"); attk = Input.GetButtonDown("Attack"); if (Input.GetButton("Cast/Heal")) { castOrhealTimer += Time.deltaTime; } else { castOrhealTimer = 0; } }
Then do tell whether it works now.
September 28, 2024 at 12:46 am #15933::Thank you for helping me. It work perfectly now. Very greatfully all of your help but I found another bug. If I’m dashing to the top of the enemy, my game is freezing and i cannot do anything. It looks like this
My character take dmg and then it freezing. It’s not the unity freeze because i still can stop the game or check the inspector. Here is the video how it happend. If this bug can fix in the up comming video so can you show me which part so i can fix it. Thanks you very much demo how the bug happend again sorry for take your time so muchSeptember 28, 2024 at 2:43 am #15934October 25, 2024 at 6:53 pm #16174::Hi so I know this is an old topic but I wanna ask that why my player casting the spell right after I realease the heal button. I remember that from the last time we fix it work ok but after a long time, I don’t really remember that did I change anything in the update method to make this bug. Would you see it for me?
<code>private void Update() { if (playerStateList.incutscene) return; getInput(); UpdateJump(); RestoreTimeScale(); if (playerStateList.dashing) return; FlashWhenInvi(); Moving(); Heal(); if (playerStateList.healing) return; CastSpell(); Flip(); Jump(); StartDash(); Attack(); }</code>
Tks you very much
October 25, 2024 at 7:52 pm #16175::It could be that the order of
if (playerStateList.healing) return;
andCastSpell();
is the other way round do swap the position for bothOctober 26, 2024 at 12:49 am #16177::Ah yes work again. Must be mine mistaken at sometime when making other function. But can I ask for why my wolf after get hit, he stuck on stunned animation but not changing to run animation even when I was stand front of him, like in the video. I make the stunned like the fly enemy guide. Is that the reason? What should I modify?
wolf stun video here is my code for the wolf<code>using System.Collections; using System.Collections.Generic; using UnityEngine; public class WolfSpririt : Enemy { [SerializeField] private float flipWaittime; [SerializeField] private float ledgecheckX; [SerializeField] private float ledgecheckY; [SerializeField] private float chargeSpeed; [SerializeField] private float chargeDuration; [SerializeField] private float jumpForce; [SerializeField] private float stunDuration; [SerializeField] private LayerMask whatIsGround; float timer; float stunTimer; // Start is called before the first frame update protected override void Start() { base.Start(); rb.gravityScale = 12.0f; ChangeState(EnemyStates.Wolf_Idle); } protected override void Death(float _destroyTime) { rb.gravityScale = 12; base.Death(_destroyTime); } // Update is called once per frame protected override void UpdateEnemyStates() { if (health <= 0) { Death(0.05f); } Vector3 _ledgeCheckStartPoint = transform.localScale.x > 0 ? new Vector3(ledgecheckX, 0) : new Vector3(-ledgecheckX, 0); Vector2 _wallCheckDir = transform.localScale.x > 0 ? transform.right : -transform.right; switch (GetCurrentEnemyStates) { case EnemyStates.Wolf_Idle: if (!Physics2D.Raycast(transform.position + _ledgeCheckStartPoint, Vector2.down, ledgecheckY, whatIsGround) || Physics2D.Raycast(transform.position, _wallCheckDir, ledgecheckX, whatIsGround)) { ChangeState(EnemyStates.Wolf_Alert); } RaycastHit2D _hit = Physics2D.Raycast(transform.position + _ledgeCheckStartPoint, _wallCheckDir, ledgecheckX * 10); if (_hit.collider != null && _hit.collider.gameObject.CompareTag("Player")) { ChangeState(EnemyStates.Wolf_Suprise); } if (transform.localScale.x > 0) { rb.velocity = new Vector2(speed, rb.velocity.y); } else { rb.velocity = new Vector2(-speed, rb.velocity.y); } break; case EnemyStates.Wolf_Alert: timer += Time.deltaTime; if (timer > flipWaittime) { timer = 0; transform.localScale = new Vector2(transform.localScale.x * -1,transform.localScale.y); ChangeState(EnemyStates.Wolf_Idle); } break; case EnemyStates.Wolf_Suprise: rb.velocity = new Vector2(0, jumpForce); ChangeState (EnemyStates.Wolf_Charge); break; case EnemyStates .Wolf_Charge: timer += Time.deltaTime; if (timer < chargeDuration) { if (Physics2D.Raycast(transform.position, Vector2.down, ledgecheckY, whatIsGround)) { if (transform.localScale.x > 0) { rb.velocity = new Vector2(speed * chargeSpeed, rb.velocity.y); } else { rb.velocity = new Vector2(-speed * chargeSpeed, rb.velocity.y); } } else { rb.velocity = new Vector2(0,rb.velocity.y); } } else { timer = 0; ChangeState(EnemyStates.Wolf_Idle); } break; case EnemyStates.Wolf_Stun: stunTimer += Time.deltaTime; if (stunTimer > stunDuration) { ChangeState(EnemyStates.Wolf_Idle); stunTimer = 0; } break; case EnemyStates.Wolf_Dead: Death(Random.Range(1, 3)); break; } } public override void EnemyHit(float _DmgDone, Vector2 _hitDirection, float _hitForce) { base.EnemyHit(_DmgDone, _hitDirection, _hitForce); if (health > 0) { ChangeState(EnemyStates.Wolf_Stun); } else { ChangeState(EnemyStates.Wolf_Dead); } } protected override void ChangeCurrentAnimation() { anim.SetBool("Patrol", GetCurrentEnemyStates == EnemyStates.Wolf_Idle); anim.SetBool("Found", GetCurrentEnemyStates == EnemyStates.Wolf_Suprise); anim.SetBool("Stunned", GetCurrentEnemyStates == EnemyStates.Wolf_Stun); if (GetCurrentEnemyStates == EnemyStates.Wolf_Idle) { anim.speed = 1; } if (GetCurrentEnemyStates == EnemyStates.Wolf_Charge) { anim.speed = chargeSpeed; } if (GetCurrentEnemyStates == EnemyStates.Wolf_Dead) { anim.SetTrigger("Death"); int DeadCorpse = LayerMask.NameToLayer("DeadCorpse"); } } } </code>
Tks for your help
October 26, 2024 at 11:26 am #16178::Can you send a screenshot of how the inspector of your transition arrow from stun to run looks like?
October 26, 2024 at 5:28 pm #16180October 27, 2024 at 3:38 pm #16190::Ok, i think you first have to reset the normal timer back to 0 when the wolf is stunned,
<code> if (stunTimer > stunDuration) { ChangeState(EnemyStates.Wolf_Idle); stunTimer = 0; timer = 0; }</code>
because when the wolf goes back to idle, the timer is still increasing, and the requirement for
if (timer < chargeDuration)
might not be met in the charge state also try changing Changecurrentanimation to make the Found bool be active during wolf charge insteadanim.SetBool("Found", GetCurrentEnemyStates == EnemyStates.Wolf_Charge);
Let me know if it worksOctober 27, 2024 at 3:51 pm #16191::So I change as you said. The animation is back to the run perfectly but for some reason, the stunned animation just didn’t run. Like in the record here
Stun animation just hit and freeze then change back to run The code as u said I change it to thisanim.SetBool("Found", GetCurrentEnemyStates == EnemyStates.Wolf_Charge);
October 27, 2024 at 4:38 pm #16194October 27, 2024 at 8:37 pm #16195 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: