Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Question about monster AI

Author
Message
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 4th May 2011 21:36 Edited at: 4th May 2011 21:54
Hello again,


I have another question about monster Artificial Intelligence.

I have one Data Type which holds all my monsters data.




And I use these data types to move my monster in my dungeons.


I have created one little complex AI code to check if my monster will arrive in a wall and changes direction or if arrive in front of one closed door or stair.

So far my code contains the wall check collision and the code works well when my monster or any monstery in labyrinth will collide on my walls , seeks for an empty square and changes direction to the empty square.

But I have problem , what is happen if one monster collide with another?

I use this AI code for monsters collision only but my monster overlaps the other one.




I thought if I use and one 2 dimensional array which holds the x and y of each monster and I put one string "01" for each square which there is a monster spot and when the monster leave the square I will change the previous square to "00" , remove the old spot and check if these 2 squares will be empty "00" in front of each other and make the collision effect for my monsters.

Would this work?
Is there any simpler way?

Thank you!

Here is whole AI code.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th May 2011 16:34
Quote: "I thought if I use and one 2 dimensional array which holds the x and y of each monster and I put one string "01" for each square which there is a monster spot and when the monster leave the square I will change the previous square to "00" , remove the old spot and check if these 2 squares will be empty "00" in front of each other and make the collision effect for my monsters."

That could work. If you use an integer which you can just increase or decrease you open up the possibility of having more than one monster in a square too...

Quel
15
Years of Service
User Offline
Joined: 13th Mar 2009
Location:
Posted: 6th May 2011 18:26
I guess the overlapping could occure because you check their states right now for collision, and after that, you move them. So a situation of stepping onto the same spot may happen.

What you should do is to have their destination locations for checking the collision. If the monster isn't moving, its destination location is the spot it is standing on right now. This way, if one monster requests a certain spot, the others won't consider that location for walking there, and overlapping can't occure.

-In.Dev.X: A unique heavy story based shoot'em ~25%
-CoreFleet: An underground commander unit based RTS ~15%
-TailsVSEggman: An Sonic themed RTS under development for idea presentation to Sega ~15%
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 11th May 2011 20:14 Edited at: 11th May 2011 20:23
I have another one question about a monster AI.

I am creating the AI code of my mummy monster and when it walks in the map and approaches in front of a closed door , the Artificial Intelligence code , checks if there is a door in front of the square of the monster and if the door is closed but not locked , the monster opens the door.
If the door is closed in front of the monster the monster tries to open it and then changes direction , if for example goes NORTH , then I call the random direction code and the monster change direction , and I check again if the random function was selected was the same as current direction and then I random it again until the new direction will be different than the current one. So the monster turns to other direction and continue walking until find another obstacle , wall or closed door or decor or player etc...
My monster according to its direction walk NORTH , SOUTH , WEST , EAST.

My type monsters(party.level,all_monsters).direction variable take values from 1 to 4 for each direction.

So if my monster walking North , I am checking the y axis value on the map minus one.



If the monster goes NORTH I check the value Y-1
If the monster goes SOUTH I check the value Y+1
If the monster goes WEST I check the value X-1
If the monster goes EAST I check the value X+1

Whole AI monster code is here:



But I have one problem , my monster opens only NORTH and SOUTH doors and ignores my WEST and EAST doors.

I have one file to see my monster and problem in action.

You are in front of a door, the door is closed and locked , the monster comes closer and you see it behind the door , when the monster arrives , tries to open the door , you can avoid it and close the door , it will try to open the door again.

If the monster arrive inside the door and you try to close the door , the the door will start close and re-open , because the mummy blocks the door mechanism , this is a good tip to kill monsters if are between doors (Remember dungeon master).

If you let the mummy pass you , will arrive at the wall and will try to change some direction , so , I have 2 doors in both directions , in my case , the mummy , must open one of these both doors , but ignore them and pass through (BUG) , but my code is correct , why North and South doors work and WEST and EAST doors got ignored by my monster?

Where is my fault?

There is a game demo attached please download an see.
Pick up a key from the alcove from the left or from your inventory.
Unlock the door from the right to release the mummy.

See my Bug

Attachments

Login to view attachments
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 12th May 2011 00:37 Edited at: 12th May 2011 01:11
I made more research and I made one experiment , I changed the order of the doors. When initialize my doors in the map I write this code:



So I change the order of the doors and I saw , my scanning loop , scans only the first door from 100 doors I have and the monster opens only the door 1 , but I have put a loop to scan all doors.



I use the variable all_monsters to check my doors insted all_doors.

But all my loop takes values from 1 to 100 so , even I use all_doors or all_monsters or all_stairs or all_decors variables is the same because all of these variables insted the name is different , is not importan the name but the value range , I would use and a very generic value for all as :



So my for next loop scans only the first of the loop , so that is the reason why , my monster ignores the rest , in fact the routine runs the only first index of my loop and ignores the rest , so if I have North doors or even West doors it doesn't matter.

How do I fix the problem? Strange I use the same technique for all of my objects in my game and works , for example when I have 3 doors to open in the game , I scan them with for all_monsters=1 to 100 and the doors interacts seperated and works well.

Do you have any idea?

I will post one demo with a lots of traps with a lots of doors a lots of items , for example I scan all my items on the floor with just one loop and it works . might the problem is not in the loops.

Is it possible when I use goto command in one loop , to confuse the loop?

For example:



In this case the goto command goes out of the loop.

But:



In this case the goto command goes somewhere inside the loop.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 13th May 2011 13:20
Further changes I tried in my monster AI functions , I discover , Monster No1 opens only Door No1 and monster No2 opens only Doors No2 in for next loop.

I tried to put more monsters in the level and Monster No1 doesn't opens Door No2.

As you have seen above I am scanning all my monsters with all_monsters variable and I use the same in doors too.

I don't know why my function is not working.
Takis76
19
Years of Service
User Offline
Joined: 9th Apr 2005
Location: Greece
Posted: 14th May 2011 01:57
Yippy I made it , now my monster AI working perfectly , I solved my problem , my mummies opens my doors any door.

now I will add smarter code , I will make monsters follow you when come close , or is you hit them the will turn direction , and other AI code , they will able to open and close doors , or press buttons.

I am very happy. If I will have any problem I will inform.
When I will have some good demo I will upload.
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 14th May 2011 19:06
Sounds interresting

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...

Login to post a reply

Server time is: 2024-11-22 22:50:57
Your offset time is: 2024-11-22 22:50:57