Another Try
by David House · in Torque Game Builder · 11/23/2007 (8:28 am) · 49 replies
OK, lets see if you like this behavior instead. The Event System behavior I had created was really just a finite state machine, so I created a new behavior specifically for that. And really this is more useful as a behavior anyway. For our game we needed a simple AI system for the enemies, so we are going to use a basic FSM for that. I also simplified how the Datablocks are created/named so it doesn't have some of the ugly indexes of the Event System datablocks I had.
The behavior has a single parameter, the name of the initial State. All the states are Datablocks that look like this:
So you have a delay & method when you first enter the state. Then a state method that is called after the state is entered, or after a repeat (when you are staying at the same state). The nextMethod allows you to determine which state to transition to (or stay at the current state). The leaveDelay and leaveMethod are called when you are leaving the state. The finally the repeatDelay is the time delay if you are simply repeating the current state. All the delays are evaled, so you can put code in there to determine the delay (for random delays).
As an example, I have a quick YouTube video:
www.youtube.com/watch?v=nG64IBhC9tw
As a test, I have a single fish and falling food. Both the fish and food are controlled by a FSM. The fish has the following states:
- MoveLeft (moves to the left side of the screen)
- WaitLeft (waits around on the left side of the screen for a few seconds)
- MoveRight
- WaitRight
- EatFood (move to a close bit of food)
The food simply has a single state DropFood with a random repeatDelay
The MoveLeft and MoveRight states move the fish and check for 2 conditions. Either the fish has arrived and it moves to the Wait state, or it finds a close bit of food, then moves to the EatFood state.
Nothing too fancy yet here (this is a basic FSM). Just wondering if anyone has any comments/suggestions. What I'm thinking of is to build some kind of GUI app to simplify the creation of the datablocks. It would be awesome to get this to a point where very little scripting is necessary (part of the point of Behaviors).
The behavior has a single parameter, the name of the initial State. All the states are Datablocks that look like this:
new t2dSceneObjectDatablock(moveLeft)
{
enterDelay = 1000;
enterMethod = "moveToLeft(%this);";
stateMethod = "";
nextMethod = "lookForFood(%this,\"-34.762 -3.92\",10.5,\"waitLeft\",\"moveLeft\")";
leaveDelay = 1000;
leaveMethod = "";
repeatDelay = 1000;
};So you have a delay & method when you first enter the state. Then a state method that is called after the state is entered, or after a repeat (when you are staying at the same state). The nextMethod allows you to determine which state to transition to (or stay at the current state). The leaveDelay and leaveMethod are called when you are leaving the state. The finally the repeatDelay is the time delay if you are simply repeating the current state. All the delays are evaled, so you can put code in there to determine the delay (for random delays).
As an example, I have a quick YouTube video:
www.youtube.com/watch?v=nG64IBhC9tw
As a test, I have a single fish and falling food. Both the fish and food are controlled by a FSM. The fish has the following states:
- MoveLeft (moves to the left side of the screen)
- WaitLeft (waits around on the left side of the screen for a few seconds)
- MoveRight
- WaitRight
- EatFood (move to a close bit of food)
The food simply has a single state DropFood with a random repeatDelay
The MoveLeft and MoveRight states move the fish and check for 2 conditions. Either the fish has arrived and it moves to the Wait state, or it finds a close bit of food, then moves to the EatFood state.
Nothing too fancy yet here (this is a basic FSM). Just wondering if anyone has any comments/suggestions. What I'm thinking of is to build some kind of GUI app to simplify the creation of the datablocks. It would be awesome to get this to a point where very little scripting is necessary (part of the point of Behaviors).
#42
added
My first inquiry in David's FSM was Posted: Dec 19, 2007 14:52. Today is Jan 31. It took me approximately 5 weeks to complete this project. Watch out GG, here I come.
Thanks
Carpenter Software
01/31/2008 (2:29 pm)
The project is now complete except for improvements. I just updated the spreadsheet above to reflect what I had done to the fighting routines. I'll post the YouTube movie (SFSM Part 4) shortly. I should warn that a blog will be set up and the images on this thread will be removed except the code.added
My first inquiry in David's FSM was Posted: Dec 19, 2007 14:52. Today is Jan 31. It took me approximately 5 weeks to complete this project. Watch out GG, here I come.
Thanks
Carpenter Software
#43
I need to read through your entire set of posts, but it looks like you did a great job!
Oh, I was also put off by 1.6 not working on my mac very well. Just downloading 1.7 now, so if its working well I'll get back into this...
01/31/2008 (5:06 pm)
Wow. I haven't been following this thread very much. Sorry for the missed responses I should have made. And yeah, I used iShowU on the Mac, loaded it into iMovie, then publish straight to YouTube. Very easy.I need to read through your entire set of posts, but it looks like you did a great job!
Oh, I was also put off by 1.6 not working on my mac very well. Just downloading 1.7 now, so if its working well I'll get back into this...
#44
@ David
I had thought that if you can do it, then so can I.
Thanks
Carpenter Software
01/31/2008 (10:51 pm)
Well here is the last movie in this project but there will be others on performance and making it look pretty as Jussi suggested above. This movie has the medium fishes, the NPC and the player, and the fighting routines, incorporated into the FSM (SFSM Part 4: Click Here).@ David
I had thought that if you can do it, then so can I.
Thanks
Carpenter Software
#45
02/01/2008 (6:27 am)
Wow! I've had my head down working lately so I hadn't been able to see the videos and I have to say this turned out great! Thanks very much for sharing the development with us, it's been quite educational for me.
#46
Thanks
Carpenter Software
02/01/2008 (8:03 pm)
Once I clean up this code and for those who may be interested, the code will be available around the first week of March.Thanks
Carpenter Software
#48
Enjoy
Carpenter Software
02/05/2008 (9:23 pm)
Here is the one on performance and of course making it look pretty. There are 10 objects cycling the FSM. It looks awesome! Also object animations added from the fish art from GG, and also background scenery and particle effects were added. Here you can view the fifth movie from YouTube - SFSM5: Click Here.Enjoy
Carpenter Software
#49
added
I assume if the game Fish FSM works in windows xp in TGB 1.7.2 on a Mac computer and it does (pretty awesome), then it will work any where!
Carpenter Software
02/06/2008 (4:41 pm)
For those who may be interested, you may download the torquescript code. I am now testing the code in windows xp. I'll let you know how that goes. I am interested in this as well.added
I assume if the game Fish FSM works in windows xp in TGB 1.7.2 on a Mac computer and it does (pretty awesome), then it will work any where!
Carpenter Software
Torque Owner Carpenter Software
Carpenter Software