Previous Blog Next Blog
Prev/Next Blog
by date

No, still no crosshair...

No, still no crosshair...
Name:Daniel Buckmaster 
Date Posted:Nov 03, 2007
Rating:Not Rated
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Daniel Buckmaster

Blog post
Sorry. Well, I can post the code changes to the crosshair I made, but I want to write a real resource with a full tutorial and usage. On second thoughts, I might just get it out there and do the scripting side of things later. Yeah, I'll do that. Okay, so I just invalidated the title of this blog entry. Meh.

Due to a week of holiday that is just coming to an end, I've had a lot more time to work on Torque than I usually do. As such, a Great Leap Forward has been made. Or several. To accompany the several Small Steps Back. Among the Great Leaps are AI coding and scripting. I added some functionality to AIPlayer so that when I tell a character to fire, it will wait for a random period of time before firing. Useless, you say? (Yes, useless, you say.) Well, not for my game. I want to, eventualy, have whole armies duking it out in a battle. As such, it's really notpossible to schedule an 'updateMe' routine on every I character with any sort of speed. So I hand out the AI to 'squad manager' entities that do all the thinking. So while I may have 150 bots a side, that's only maybe 12 squads, so only 24 (in total) objects doing any sort of complicated thinking.
Of course, there's problems with that approach. One of which is the firing. If a squad manager is running its 'tell the squad when to fire' routine every second, then every second, all the AIs in the squad fire a shot. They wait a second, then fire a shot. Uncanny. So the solution was pretty easy to find - simply add a random delay to when an AI character fires. Schedule would have been the easy way out, but I'm staying away from it as much as possible - even the squad manager thinking routines, I want to move into code, or at least partially. And anyway, you run into the same problem as before - you're scheduling for every individual character, which basically defeats the purpose of using a squad manager at all. So I decided to just move that functionality into code.
A little while later, and I had the AIPlayer::singleShot method. It takes two parameters, minimum and maximum values for the random delay. After that length of time in ticks, the AIPlayer triggers a script callback on itself, and in that script callback, I do stuff like set the character's image trigger, etc.
So that's how it'll work. Each time the squad manager runs through its 'tell people to shoot' routine, it does just tht - and the result is that you get a smattering of gunfire that looks nice and natural.

Recent Blog Posts
List:05/07/08 - The Onager Engine
11/03/07 - No, still no crosshair...
09/01/07 - Second blog post!
08/07/07 - First blog entry...?

Submit ResourceSubmit your own resources!

You must be a member and be logged in to either append comments or rate this resource.