Forum begins after the advertisement:
[Part 10] Boss doesn’t flip
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 10] Boss doesn’t flip
- This topic has 19 replies, 2 voices, and was last updated 9 months, 1 week ago by Terence.
-
AuthorPosts
-
March 13, 2024 at 8:15 am #13546::
I think I either found a problem with the boss controller, or I just typed it wrong XD the second part of the conditions should be greater than, right?
<code>#region health to state if(health > 20) { ChangeState(EnemyStates.Boss_Stage1); } if(health <= 15 && health < 10) { ChangeState(EnemyStates.Boss_Stage2); } if(health <= 10 && health < 5) { ChangeState(EnemyStates.Boss_Stage3); } if(health < 10) { ChangeState(EnemyStates.Boss_Stage4); } if(health <= 0) { Death(0); } #endregion</code>
March 13, 2024 at 6:59 pm #13551::Allan, you’re right. There’s been a mistake. What was intended was probably this:
if(health > 20) { ChangeState(EnemyStates.Boss_Stage1); } if(health <= 15 && health
<> 10) { ChangeState(EnemyStates.Boss_Stage2); } if(health <= 10 && health<> 5) { ChangeState(EnemyStates.Boss_Stage3); } if(health <105) { ChangeState(EnemyStates.Boss_Stage4); } if(health <= 0) { Death(0); } #endregionBut I will do it like that using else if structures instead so it’s more efficient (and easier to read as well):
if(health > 20) { ChangeState(EnemyStates.Boss_Stage1); } else if(health > 15) // Gets between 15 to 20 { ChangeState(EnemyStates.Boss_Stage2); } else if(health > 10) // Gets between 10 to 15 { ChangeState(EnemyStates.Boss_Stage3); } else if(health > 5) // Gets between 10 to 15 { ChangeState(EnemyStates.Boss_Stage4); } else { Death(0); }
March 15, 2024 at 5:55 am #13562::Just found out that in the BossController in AttackHandler() there’s the line
int _attackChosen = Random.Range(1, 4);
but with integers the upper range is exclusive, so it should be (1,5). Funny thing is, that with floats the upper range is inclusive lol In the end I couldn’t make the different phases work, and the dive attack would stuck the boss in the air with the jump animation, even when dive was set to true, or jump to false, nothing would unstuck it. So I just made it one boss, doing random attacks with whatever worked haha hitting the boss during outbreak made him fall on its head hahahahOn the weekend I might post all my codes here for reference, there are many bugs though XD but I did solve many more that were presented in the videos lol
March 15, 2024 at 6:58 am #13563March 16, 2024 at 2:48 am #13577::Just found out that in the BossController in AttackHandler() there’s the line int _attackChosen = Random.Range(1, 4); but with integers the upper range is exclusive, so it should be (1,5). Funny thing is, that with floats the upper range is inclusive lol
Thanks for this spot. Yup, there is actually a very good reason for this. The integer version ofRandom.Range()
is often used to get a random item in an array, for e.g.arr[ Random.Range( 0, arr.Length ) ]
. If we made the end value inclusive, then the expression will have to becomearr.Length - 1
.The reason you can’t do this for floats is because if it is exclusive, then there is no way to get a number between a and b. For example, if it was exclusive, I would have to do something like
Random.Range(0, 1.001f)
to get all numbers between 0 and 1, but this will include all numbers between 1 and 1.001f as well.In the end I couldn’t make the different phases work, and the dive attack would stuck the boss in the air with the jump animation, even when dive was set to true, or jump to false, nothing would unstuck it. So I just made it one boss, doing random attacks with whatever worked haha hitting the boss during outbreak made him fall on its head hahahah
We’ve started working on the revamp for the Metroidvania series. I’ll be happy to get Joseph (he’s the guy vetting the series and applying the fixes) to fix your bugs for you, but can you help me compile a list of the issues (and the corresponding part, if possible) you have for him? This will be really helpful for him because he has a large list of issues to go through.On the weekend I might post all my codes here for reference, there are many bugs though XD but I did solve many more that were presented in the videos lol
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: