GameMaker [SOLVED] Where do I put it? (That's what he said)

Good day,

I'm working on enemy AI at the moment. I have a state machine with 10+ states (in a switch).
The states change as they should but I have lots of problems with collision checks (they don't seem to work) so my question is this.

Where do I put those checks?

I've tried to put it...
* ... in all kinds of step events (begin/step/end).
* ... first & last in said events.
* ... in a script where I've called it like stated above.
* ... Calling the said script form inside every case in the switch.

Still it completely ignores walls and stuff and behaves like a flying ghost.
 

JasonTomLee

Member
Could you post some example code?

The collision code probably got tangled inside the state-machine. And whether its in the begin/end step Event shouldnt matter in this problem ( though collision checks should be applied in the Begin & movement applied in the End Step )
You should generally try to batch all the code in sections: AI behavior, Collisions, code that sets states, Draw events, etc...
 

samspade

Member
It depends. Generally I do everything in one step event. So the code looks something like:

///step event
- state machine
- collision

Where all the state machine code is run first (in a switch) and then collision is run. However, in many cases you can get away with only putting the collision code inside of the specific state.

That said, location of the collision script is not likely to matter in the way you described. Generally collision and movement happen together - in other words your velocity (commonly hsp or vsp) is only added to your position (x and y) after checking for collisions and finding any collision reduces your velocity to 0.

If your object is moving then it seems that your collision code itself is not working. Posting the code would help solve this issue (as JosonTomLee pointed out).
 

NightFrost

Member
Not sure how state machine would be the culprit here, instead of bugged collision code. No matter what the state, whenever you need to update position you set the deltas and wrangle them through collision checks.
 
@JasonTomLee && @samspade && @NightFrost
You were all right of course. I'd messed up the collision checks.
I find it a bit overwhelming writing a state machine this big, I've never done it before and although it's crazy fun it leaves me highly confused more often than I'd like.

Either way, thanks for setting me straight with your input guys!
 
Top