Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

Enemy A.I.?


Asuma

Recommended Posts

It depends of the behaviour itself. It depends of what you want to use. Actually, the best way should be to have custom static engines for each object, but it consumes cpu. On MMF you should be able to use some built in movements to make small things. the one i most use is the bouncing ball movement, since it allows to move freely on every direction and allows you to change the movement pathern when you want to.

Actually, AI dependes more of the enviroment than the movement itself. The easiest way i found for doing AI is by having an alterable value that indicates what to do.

For example, want a badnik that drops over sonic when he passes under the robot? It's easy:

Bouncing ball movement.

At start of frame set alterable value a to badnik.x

set alterable value b to badnik.y

if alterable c equals 0

+only once

badnik.set speed to 30

badnik.set direction to left or right

if alterable c equals 0

+ badnik.x < badnik.alterable a -100

set badnik.direction to right

if alterable c equals 0

+ badnik.x > badnik.alterable a +100

set badnik.direction to left

if alterable c equals 0

+ badnik.x < sonic.x+16

+ badnik.x > sonic.x-16

set alterable value c to 1

if alterable c equals 1

set speed to 100

set direction to down

if alterable c equals 1

+ badnik. collides with bg

set value c to 2

if alterable c equals 1

+ badnik.y > alterable value b + 200

set value c to 2

if alterable c equals 2

set speed to 10

set direction to up

if alterable c equals 2

+ badnik.y <= alterable b

set value c to 0

set badnik.y to alterable b

more-less.

Also, another recomendation. If you have to use sensors to detect positions, while possible, put them in sonic instead of the enemy. For example, if you want to change that the above badnik detects sonic position with a sensor, you should put the sensor onver sonic instead of having one sensor for each baddie.

I hope that helps.

Link to comment
Share on other sites

Actually there is a way to detect ground collision without any sensor. There is an event under the gameplay object that is collision mask-> is an obstacle?

with this, you can detect if a position is an obstacle. So you can say

is character.x, character.topy an obstacle? and you will know if the top pixel of the character is an obstacle or not. It helps avoiding to use extra objects, but it requires patiente for making the events to work (since events tend to aply to every object instead the colliding one or just to the last created object) and it's less accurate than a sensor, but with some skill, you will be able to do it.

I think Larkss is refering to that, right?

Link to comment
Share on other sites

Might as well reply to this than make my own topic. I'm attempting something I've never done before: Platformer AI which uses sensors. So far, things seem to be working smoothly in terms of gravity and giving each AI it's own sensor objects. It starts off like this:


Always
*Start loop "AI", number(AI-Mask) times

Start of Level
*Spread Value 0 into alterable value A of: AI, AI-Mask, AI-Floor Sensor, AI-Gun

On loop "AI"
+ Alterable Value A of (AI-Mask) is == LoopIndex("AI")
* Set sensor positions relative to the AI-Mask object.
[/CODE]

In-game, each AI ( and its sensors) has it's own unique value assigned to it. and those sensors and AI are paired together based on their values. This all looks like it's working, and when I add gravity, it appears to be working as well. However, things started getting complicated, and now everything is a total mess. The AI just walk back and fourth, patrolling an area marked by marker objects. When you get near, I wanted them to be able to do one of these two options: 1) Stop their movement, AI-Gun object faces at the player and they fire occasionally, or 2) Look in the players direction, AI-Gun is set to look at player, and they follow you while shooting as long as you are in their view distance (which too is a sensor assigned to the AI's).

When I try to add attacking, things start messing up, and when one AI sees you, they all do. At this point they all act as one, and I've spent hours going over it and making changes, but so far it looks like nothing I do fixes the issue. I guess to simply this all up, I'll write down roughly what I'm trying to accomplish.

AI patrols area if player not spotted. Walk back and fourth until they collide with a marker object which makes them turn the other direction. Simple. When the player enters the AI's "view distance" object, it and it [i]alone[/i] will react to you and fire, while the other AI remains patrolling as he is unaware of your being (currently, one sees you, they all do).

[CODE]
//I'm trying to make it do this
If player is overlapping AI-view
+if AI-view and AI-Mask are both assigned to each other.
*Make the mask assigned to above view object change it's A String to "attack mode" and act accordingly.[/CODE]

I've made AI before, but never anything this complicated. I've done some searching and could not find any tutorials or examples which can help me along with this. If it were only 1 AI, this wouldn't be a problem, but there will be many in the level which is making this a giant pain. Does anybody here think they can give me a hand, tell my my errors, or point me in the right direction here?

EDIT: If anyone is wondering, no movement extensions are being used. I'm trying to make each AI have it's own Static Movement.

Link to comment
Share on other sites

Copy and Paste from MMF2 Help:

Spread value

This action is quite powerful and allows you to spread numbers in an alterable value of multiple instances of an object. Imagine you have 10 instances of an object called "Ball". If you spread a value in Alterable Value A of the Ball object, starting at 1, the first object will have the value 1, the second the value 2, the third 3 etc. up to 10.

---

Anyways, I've managed to fix the AI problems I was having. Had to pretty much remove almost everything I had on there besides gravity and start over.

Link to comment
Share on other sites

Spread Values are a function that help MMF distinguish one object from another, but sadly for more complicated uses its quite useless.

you have to combine it with the Fastloop object (or in my case, the Array Object) for it to really be of any use in complicated AI.

Link to comment
Share on other sites

Okay, the AI seems to work for the most part. Enemies stop and shoot at you when spotted, and if that's not the case they patrol their marked areas. A shame how I'm having so much trouble with such simple AI. >_>

I've created a debug spawning button which allows me to create a bunch of AI on the playfield to make sure everything is working correctly. They spawn without problems (sensors and the like are attached correctly), and when each AI is destroyed, its sensors are destroyed with it. Now only one visible problems remains. Each bot has a sensor attached, and when you shoot at this sensor, it's supposed to subtract more health to the AI its attached to than if you were to shoot it anywhere else. When I shoot the sensor, it subtracts health from all the AI, which I don't really get why it's doing this.

//This is used to try and keep the sensors and AI's "health" together as one.

ID of (AI) == ID of (Ground Sensor)
* Set health of (Ground Sensor) to health of (AI)

ID of (AI) == ID of (Gun)
* Set health of (Gun) to health of (AI)

ID of (AI) == ID of (Headshot Sensor)
* Set health of (Headshot Sensor) to health of (AI)

//This is the headshot detection code, which apparently isn't working.
(Bullet) collides with (Headshot Sensor)
Id of (AI) == ID of (Headshot Sensor)
* Subtract 5 from health of (AI)

//Removing dead AI and their sensors
Health of (AI) &lt;= 0
*Destroy AI

Health of (Ground Sensor) &lt;= 0
*Destroy (Ground Sensor)

-Pretty much just repeat the above for all other sensor objects-

Link to comment
Share on other sites

//This is the headshot detection code, which apparently isn't working.

(Bullet) collides with (Headshot Sensor)

Id of (AI) == ID of (Headshot Sensor)

* Subtract 5 from health of (AI)

And here is why MMF pisses me off.

Technically, its supposed to work, but im guessing its subtracting from all of the enemies because it still isnt distinguishing the objects correctly.

From my experience, you're just going to have to change the order of that event around and study how it works.

If i were you, i would change it to :

(Bullet) collides with (Headshot Sensor)

(Headshot Sensor) ID == ID of (AI)

* Subtract 5 from health of (AI)

That way, MMF2 chooses the objects like so :

Bullet --> Collision with *this specific headshot sensor*

V

*This specific headshot sensor having collision*'s ID = ID of (AI)

V

Subtract from AI -5.

You're trying to narrow down to a specific object. Apparently, unless you do it certian ways, MMF2 still is finding a way to associate ALL of the AI's into the conditions you're setting. You're going to have to find a way to seperate them.

Simple in theroy, but trust me this is going to piss you off to no end until you get it right. (or quit.)

  • Like 1
Link to comment
Share on other sites

I took you're advise and changed around the code. Still didn't seem to work. Cursing MMF2, I try one last thing.

(Bullet) collides with (Headshot Sensor)

+Id of (Headshot Sensor) == ID of (AI)

+(Headshot Sensor) is overlapping (AI)

*Subtract 5 from AI Health

---

Surprisingly it actually works. I've tested it multiple times and I guess the problem is finally solved. All that's left to do now is maybe make the AI more interesting and polish things up a bit (ex. adding a death animation when the AI is killed instead of just removing them form the playfield). Thanks for the help, rep'd.

Link to comment
Share on other sites

Let me just remind you all that state-machines are an excellent way of controlling enemy behaviors.

In terms of the standard movement, I personally just tend use simple X position and X velocity variables and call it that. Sonic games almost never feature really complex movement and they make a point of avoiding slopes for enemies that move left to right (usually opting for something that just jumps up instead). The only exception I can recall is the roller, and I imagine it was carefully scripted to go a certain slope and then do it's jumping thing when it hits certain objects rather than actually just working by detecting the slope and all of that madness. I doubt the genesis could have handled any small number of enemies with movement complex enough to handle that dynamically while simultaneously doing everything else it was doing.

That said, there are some tricks they would use for left to right motion down hills that didn't really require a whole lot of slope management or anything like that. For instance, bouncing objects, placing segments a certain y value above the ground, etc.

Going on with that, if you really wanted to, you could have two different states for an enemy moving along regular terrain and complex terrain. Whether or not it's on which terrain could easily be detected using only two sensors.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...