help with making this enemy move and attack at same time

Started by
2 comments, last by kyleloii 11 months, 2 weeks ago

okay so, I have a enemy im trying to get to chase and attack at the same time and this is whats happening, its getting stuck in attack i think https://gyazo.com/37f14406648a11138f6fc79bf50f39b7 here is the related code https://gdl.space/tititajoyo.cpp https://gdl.space/xulatoroxi.cs https://gdl.space/tasitakusa.cs Does anyone have any idea how i can make this work? been bangin my head against a wall for 2 days now

this is what i want to happen https://gyazo.com/ddd2fb1f607a284eaec4e344f835cc0f but it only happens when i add or remove a condition from attack to idle?

also im following this tutorial but he doesnt include animations :

https://www.youtube.com/watch?v=b8YUfee_pzc&t=13637s

Advertisement

In programming you're wrestling two forms of reality. The concrete form of reality is the code. The more abstract form of reality is your understanding of how it should behave in every possible situation. When these two forms of reality don't match, we call it a bug. The question is however always, which form of reality is wrong. Without knowing that, you cannot fix anything.

In either case however, the first step in fixing is to understand *exactly* where the code is making the wrong turn. In other words, where do both forms of reality diverge from each other?

So rather than trying to fix things, first start with understanding what exactly is wrong. Make a copy of the code, and then do *anything* you think will improve understanding of its concrete behavior. (Really anything!)

A very non-exhaustive list to give some ideas:

  • make a movie and analyze frame by frame if it helps. You may want to extend the visual display with internal information, like change color if it's internal state changes, or display values of some key variables, scale the display to the 200x200 area where the problem happens so you can see better what happens.
  • if there is too much information to display, you can opt for dumping all data to file each iteration, and analyze that data afterwards,
  • another trick is to simplify the problem by eliminating non-relevant parts of it. (Disable some code by putting it in comments, run the code again to verify the behavior is still broken, and if so, delete the commented code, repeat as often as needed.)
  • If you're reasonably able to pinpoint the exact spot, you can use a debugger, set a breakpoint just before it and trace the steps that it does line by line.

There are many approaches here, there is no one-size-fits-all. Keep in mind, you're trying to get to the root cause of the problem, everything you do is temporary hacking for that purpose here.

With patience and some work you will eventually find the spot where the code makes the wrong turn wrt to your understanding. Once you found it, *think*. Is it reasonable that the code is doing what it's doing?

  • If no, the concrete reality is broken and you found out where and how the code decides wrongly. Some code needs fixing!
  • If yes, then your understanding reality is broken. This is the harder case, you'll have a form a new idea of how it should work. Once you (think) you found that (which can be a hard problem in itself), you also know how to change the concrete form of reality. More often than not this causes large changes.

Good luck!

@undefined thanks for the answer! I think I Found the root of the problem!

This topic is closed to new replies.

Advertisement