Enemy AI Platform Char.. Floating Upwards & Shaking like Parkinson's Disease?

How do I…

Get an Enemy AI to behave like a normal platform character while moving to specific objects on the screen using the pathfinding behavior? The objects are falling randomly from the top of the screen towards the bottom of the screen. At any time there are possibly 20+ objects on the screen. The enemy AI should avoid the falling objects that it doesn’t want and collect the objects that it does want. It currently has pathfinding and platform behavior.

What is the expected result

The enemy AI should run left, right and jump. It should avoid and dodge objects that it doesn’t want to collect, while moving to the object that it does want to collect. It should not be able to defy gravity and float upwards towards an object which is on a much higher level.

What is the actual result

Right now, it’s moving towards a specific object but not always staying grounded like a platform character. It doesn’t always stay on the floor. Sometimes (but not always) the enemy AI will float upwards towards one of the objects that it’s after. So it will completely defy gravity of the physics engine and appear as if its flying or floating.

And sometimes it will get stuck if there is a platform in the way and won’t try to jump over the platform. It just keeps moving into it while staying stationary , the run animation will keep playing as the Enemy AI is pushing up against the platform but it won’t try to jump over. Also, when the enemy AI does choose to stay on the ground and walk left and right, it seems to be bouncing up and down erratically. Trembling like it has Parkinson’s disease. How do we cure it’s Parkinson’s?

How to make the Enemy AI avoid falling objects that it doesn’t want?

I’m thinking if I should also use raycasting to try to avoid other objects. I’ve never used it before. Or to attach large (invisible) sprites to the objects so that if a collision is detected, then the enemy AI will take evasive moves when it hits that larger sprite, before it hits the unwanted falling object. Although I wonder what happens if several simultaneous collisions are detected in that scenario…
Any ideas the best approach?

Additional question about Compare Two Strings

Will this Compare Two Strings logic work, specifically the “.oldvalue”?

VariableString(LLimit) ≠ VariableString(LLimit.OldValue)

1 Like

The pathfinding is made for top-down AFAIK, not for side-view platformers, so you would need to completely change your logic.
To avoid falling objects, maybe simply compare the X position of enemy and objects?

Regarding your string question, you make LLimit a standard variable on one side, and a structure with a child on the other, so it cannot work.

1 Like

Thanks Gruk, I had a vague inkling that pathfinding doesn’t work with platform behavior. I guess it must have crossed my radar before but elsewhere recently I heard that you can use the grid system to make pathfinding work, albeit still not effectively. Not sure if that’s true though or just speculation.

I’ll try raycasting and distance to position instead. Envisioning it now, it may be a lot more complicated than I initially thought since I’ll have to code many enemy AI moves for certain scenarios, instead of letting a pathfinding algorithm automate it all as I’d hoped. But it’ll be fun to see it all finally come together. I better go read up on raycasting :slight_smile:

That sounds like an interesting game. How does the player fit in?

You said there were platforms. If the platforms have the platform behavior then you can give the enemy the platformer character behavior instead of physics. Just disable the [use default controls] under the platform character behavior and then you can control the enemy through it’s object using simulated actions.

It wouldn’t be easy but it could be fun to make and there are plenty of people willing to help you.

It would envolve a collection of things like checking the x,y for edges of a platform and simulating the jump key and like you said, you can use raycast or collision detection to control the left and right for movement and avoidance.

1 Like

Yeah, basically, you’re trying to make a platformer that plays on autopilot. It doesn’t sound easy.
Good luck!

1 Like

Thanks Keith, very useful info. I’ll try to use a combination of all those things to get the desired result. The player comes into this because they’re collecting specific objects too. Whenever an object is collected it will damage the opponents health bar. So the Enemy AI is basically the simulated one-on-one opponent. Think of a fighting game, but instead of inflicting damage with physical attacks, you do the damage by collecting the correct objects! I wanted to make it a multiplayer online game originally but then I realized that combating an AI opponent in single player mode would be more fun than just doing a sort of points system.

You mentioned that i could remove the enemy physics behavior and just use platform behavior, in conjunction with platforms having a platform behavior. What do you think are the advantages to that approach - i mean specifically removing the enemy physics? I guess I don’t really need the enemy to have a physics behavior as long as it’s still behaving like a platform character and abiding by the laws of gravity!

lol… that’s pretty much it in a nutshell. The level sizes are set to be very small, only one or two screens per level. Rather than a platform game with long stretched out levels. So hopefully that’ll reduce the complexity!

1 Like