Is there built-in AI in TGB? And if so...
by Chris Jorgensen · in Torque Game Builder · 09/12/2006 (12:49 pm) · 27 replies
How would I use it?
If not, has anyone out there done AI in script? And how did you go about doing it?
I did a simple one which, while pretty stupid, has done the trick for testing purposes. I basically created a script object and assigned it to a ship. Then it would call the same functions the human player controls call based on if it decision. But I don't like how I wrote it. Basically, every half second it would look at itself, its surroundings, and its experiences (just some feedback controlled decision thresholds), and decide if it wanted to attack, evade, or search.
It's problems:
1- too slow at making decisions
2- hard to balance ratio of attack/evade
3- does a poor job aiming at other ship (fires at where its target is, not where it will be)
Anyway, just curious if others have tried this, or if it's insane to to AI in script.
If not, has anyone out there done AI in script? And how did you go about doing it?
I did a simple one which, while pretty stupid, has done the trick for testing purposes. I basically created a script object and assigned it to a ship. Then it would call the same functions the human player controls call based on if it decision. But I don't like how I wrote it. Basically, every half second it would look at itself, its surroundings, and its experiences (just some feedback controlled decision thresholds), and decide if it wanted to attack, evade, or search.
It's problems:
1- too slow at making decisions
2- hard to balance ratio of attack/evade
3- does a poor job aiming at other ship (fires at where its target is, not where it will be)
Anyway, just curious if others have tried this, or if it's insane to to AI in script.
About the author
Owner of Cascadia Games LLC
#22
there is no difference between
in terms of functionality they are 100% the same test
09/27/2006 (8:47 am)
@Johnthere is no difference between
if ($var == true) ; if ($var);
in terms of functionality they are 100% the same test
#23
TorqueScript Reference.pdf covers a whole bunch of the operators in TorqueScript, which are basically the same across languages.
To answer your question simply - 2 && 3 are exactly the same and programmers will tell you to use 3 because it's simplier and (eventually, perhaps) more intuitive.
And I wasn't up too late - I'm interning at GG and therefore have been voluntarily chained to my laptop.
EDIT: Foiled by Ben!
09/27/2006 (8:47 am)
@ John:TorqueScript Reference.pdf covers a whole bunch of the operators in TorqueScript, which are basically the same across languages.
Quote:"EDIT- By the way, any difference at all between 2 & 3?They are exactly the same to the computer. The if statement is going to try to resolve the statement into a boolean (true/false which is 1/0). So, just putting the boolean $rightPressed in there is going to be true when $rightPressed is true and false when it's false. #2 is going to do the same thing. If you wanted the if statement to be true when $rightPressed is false, you could use
if( !$rightPressed )The "!" operator negates the boolean. This would be equivalent to using
if( $rightPressed==false)
To answer your question simply - 2 && 3 are exactly the same and programmers will tell you to use 3 because it's simplier and (eventually, perhaps) more intuitive.
And I wasn't up too late - I'm interning at GG and therefore have been voluntarily chained to my laptop.
EDIT: Foiled by Ben!
#24
09/27/2006 (10:20 am)
Also, as I was getting at in your original thread: it would be cleaner to have animations based on the actions, not the input. Let the actions be based on the input and derrive animations from that. So, for example, if($player.walkingLeft) instead of if($leftPressed). That way you can get your walk animation to stop when you hit a wall, regardless of whether or not your user is pressing the left key.
#25
An interesting way to look at it. So keyboard input or a collision is still used to change states, but you mean that the state itself is the animation. I think I might be on the right track...
Last night, I was considering using schedules to determine whether the player has just stepped forward (first 250 miliseconds) or has been walking for 2 secs. That way, I can still have a stronger attack if you step + attack, and the player can run after walking for a couple seconds. (Works in "Turtles in Time", Konami's 2nd Ninja Turtles game)
Is there any documentation on FSMs? I really know so little about the programming language, but I do understand the concept. If I could just see how to make a guy stand there and breathe, then walk in one direction until hitting a wall or no longer pressing a direction, I know I could piece the rest together. (Except for the more advanced stuff like AI... and a few other things that sound easier than AI)
@Eastbeast: Not foiled. I didn't know about the !. Or should I say I !knew about the !? && I like the way you used the double ampersand... I'll remember that when I add "and" conditions.
09/27/2006 (6:26 pm)
@Thomas: Oh!! That's what you meant...An interesting way to look at it. So keyboard input or a collision is still used to change states, but you mean that the state itself is the animation. I think I might be on the right track...
Last night, I was considering using schedules to determine whether the player has just stepped forward (first 250 miliseconds) or has been walking for 2 secs. That way, I can still have a stronger attack if you step + attack, and the player can run after walking for a couple seconds. (Works in "Turtles in Time", Konami's 2nd Ninja Turtles game)
Is there any documentation on FSMs? I really know so little about the programming language, but I do understand the concept. If I could just see how to make a guy stand there and breathe, then walk in one direction until hitting a wall or no longer pressing a direction, I know I could piece the rest together. (Except for the more advanced stuff like AI... and a few other things that sound easier than AI)
@Eastbeast: Not foiled. I didn't know about the !. Or should I say I !knew about the !? && I like the way you used the double ampersand... I'll remember that when I add "and" conditions.
#26
09/27/2006 (11:27 pm)
I'm sure you could find a lot about FSM's by a simple google search. Just make sure it's Finite State Machine and not Flying Spaghetti Monster. I came across that one a while ago! ;)
#27
I'm getting married in two weeks, and my parents will arrive in Hong Kong on Monday. So I better keep my test run simple. (Stand + run + poorly-animated-jump oughtta do the trick!)
If this works, I owe several Toms (including Mr. Feni) and non-Toms my thanks. Actually, thanks either way. The helpful responses I get in this forum never cease to amaze me!
09/29/2006 (9:04 am)
Actually, I think I found a super helpful thread in here, which says I can load animations like this:Quote:$playerStandState = new ScriptObject() { animation = playerStandAnimation; };
I'm getting married in two weeks, and my parents will arrive in Hong Kong on Monday. So I better keep my test run simple. (Stand + run + poorly-animated-jump oughtta do the trick!)
If this works, I owe several Toms (including Mr. Feni) and non-Toms my thanks. Actually, thanks either way. The helpful responses I get in this forum never cease to amaze me!
Torque Owner Robert "Robc" Charney
is often a nightmare for me too, sometimes this can be a difficult error to find because the unintended assignment can actually occur inside the if statement causing all kinds of subtle problems.