2. May 2012 14:58 by Squize

Now Outpost:Swarm is live I thought it may be an idea to explain how I did your in-game partners AI.

If you've ever read up on Boids you'll know they have 3 simple rules,

Separation

Alignment

Cohesion

And all the examples you'll see are bird like objects flying around, maybe towards your mouse pointer, maybe avoiding obstacles. All seems simple enough. Adding them to a real game however quite a bit trickier.

For separation we have to ensure the NPC is avoiding both the player and all the baddies. Firstly we find the distance to the players sprite using a simple

distance=dx*dx + dy*dy;

Like you would in your usual circle to circle tests. If we're too close then we need to repel the NPC from the player, via:

tmpPoint1.x+=dx+dx;

tmpPoint1.y+=dy+dy;


Where tmpPoint1 is just a new Point(0,0);

That's part 1 of the test done, the second is checking against all the baddies, and there can be a load at any one time. What I did was use a flip flop, every even frame we get a list of all the possible neighbours ( Baddies which are close enough to care about, if they're on the other side of the screen then we can skip them ), every odd frame we do exactly the same distance check as we did above.


Finally we divide our Point value,


tmpPoint1.x/=speedDivisor;

tmpPoint1.y/=speedDivisor;

( private var speedDivisor:Number=20; )

 

This keeps the values within a respectable range so we don't move too fast.

Outpost:Swarm

The next rule is alignment. Lucky for us we don't care about that in this case, we're not creating a flock of birds or swarm of insects, we just want one guy to look fairly smart and follow his friend around.

Cohesion in this case means following. We do another distance check to the player, but this time with a greater radius ( We want them close and for the NPC not to lose sight of the player, but we don't want them virtually kissing. That's planned for the sequel, Outpost:Date&Fuck ).

var dx:Number=bodyXPos-targetX;

var dy:Number=bodyYPos-targetY;

var distance:Number=dx*dx + dy*dy;

if(distance<3000){

  tmpPoint2.x=tmpPoint2.y=0;

  return tmpPoint2;

}

 

tmpPoint2.x=(targetX-bodyXPos)/speedDivisor;

tmpPoint2.y=(targetY-bodyYPos)/speedDivisor;


Note the use of targetX/Y, rather than PlayerX/Y, we'll come back to that at the end of my presentation. As you can see, it's pretty much the same thing as before, and something I'm sure most of you have done with your circle to circle checks.


Right, we've got two Points after running our rules, time to calculate the NPC's velocity.


velocity.x=rule1V.x+rule2V.x;

velocity.y=rule1V.y+rule2V.y;


Then we do a quick test to make sure the velocity in both directions isn't greater than the max speed we've set for the NPC, we don't want him outrunning the player ( Or actually, not to outrun the player enough that people will notice ).

The next part was the tricky one, we can move him around fine, but what about the walls ? It turned out to be surprisingly simple. We use good ol' tile based checks. If there's a wall on the horizontal of the NPC we set velocity.x=0; and then the same with the y. 

We're finally there, we just finish off with

sprite.x+=velocity.x;

sprite.y+=velocity.y;


Cool, and that's how you can use Boids in real life ( The same principle handles the baddie movement ).
 
Let's test that out in game. Excellent it works, and if I manage to lose the NPC behind a wall then... oh tits, he'll just sit there. That's not a great look for a hard as nails space guy with a big ass gun.
 
Check this level map out,  

AI path

Within each level we lay down a path for the AI. Every couple of frames we look to see if the NPC can "see" the player using a line of sight. If he can't it means we've ditched him behind a wall.
When that happens we fire out 4 rays from the NPC until it hits one of those path tiles ( Remember at the heart of the game is a tile engine running alongside the purely physics based one ). Once we've done that we can easily find out which is the nearest part of the path, we change the TargetX/Y ( From above ) to our tile and the same code that moves him towards the player moves him towards the path.
All the time we're moving towards the path we're doing our line of sight checks to the player, if we spot him again we break off from the path and go back to following the player.
 
It's not fool proof, if he gets lost then he's only going to make his way to the path and then not do anything really clever, but because the levels are small enough you should soon bump into him again to get him following the player. Also, he doesn't really need to be that smart when he's off on his own, we just want to create the illusion that he's not a dumb arse, he doesn't need to be Stephen Hawking ( Perhaps not the best example when talking about movement ). Finally, we're still using Flash, we don't have all the CPU time in the world to do something really fantastic.
 
And that's how we move the NPC.
 
Squize.
 
PS. Wow, looks like I've got about 40 fonts / sizes in this, nasty, but it took enough time to write this up, I'm going to swallow it looking slightly ugly.
1. May 2012 19:59 by Squize

Obscure film references.

DN8:Pulse

Get your bullet hell / stage3D doesn't work on your computer fix over at TurboNuke now and make both of us happy.

A huge thank you to everyone who helped with this.

Squize.

30. April 2012 19:20 by Squize

DN8:Pulse

Get your GPU's ready.

Squize.

26. April 2012 16:44 by Squize

Outpost:Swarm, currently exclusive to Miniclip.

Outpost:Swarm

Thanks to everyone who helped us make it what it is.

Now, back into the dark again...

24. April 2012 16:37 by Squize

This time, you're not alone.

Outpost:Swarm

Squize.

17. April 2012 00:23 by Squize

We really like FlashMush, Robbie is reviewing lots of games and doing a really good job of it.

Because of that we asked him if he'd be up to review DN8:Pulse before release, and he said yes, and I said cool and then he reviewed and now I'm linking to that review.

Straight forward enough.

Go here my young beauties if you want to see if our game was good or a bit shit ( Hopefully by now you'd know we'd still write this post even if it was a bit shit, but without spoiling things too much, it has a happy ending ).

Squize.

PS. Outpost:Swarm is still waiting sign off, DN8:P is waiting for someone to buy it, the Android version is coming along albeit slowly and we've started a new game which I guess we'll talk about soon enough.

Tags:

News

2. April 2012 20:34 by Squize

I've been meaning to write up a postmortem for Outpost for months now, just never have the time.

Lux has been the same, but cracked and found some time today. If you're interested in how the look & feel and overall design came about shoot on over to Lux's blog here. It's a great read, even I got new insights ( Even though we work really closely together we don't go through thought processes all the time, so there's always lots of "Ah, that's why you did that" moments ).

You'd think this would be spur me on to write mine wouldn't you...

Squize.

28. March 2012 15:35 by Squize

We're getting there.

New in from last time are Perks. These are as you'd expect, unlocked at a certain rank and there are 3 available at once from a total of 6. There's nothing really earth shattering about them, it was more a way to justify XP / Challenges ( Which I've still got to do, but can't really face ).

Also we've got more levels in there now, I'm just starting on level 9 ( It's a bit of a slog ), there are some asteroids in the background to go with the planets which add a little something and the save routines have been tidied up a lot.

I'm trying to think what else has gone in there, obviously nothing too astounding otherwise I'd remember it ( I will the second I post this ). Hopefully either tonight or tomorrow I should get some new music and player sprites to go in there which I'm really looking forward to. Ah, pause mode, I think that's new from last week. How grasping at straws am I.

Shall we do a little beta ? If you fancy giving it a go post a comment and I'll hopefully post something up tomorrow ( via email, not the blog ) and then you can let me know I'm deluded and it's not really all that. Cool, it's a date then.

Squize.

21. March 2012 18:54 by Squize

Another pretty productive week on DN8:Pulse.

Particle orgy

I've managed to get all the player power-ups in there, and today added the first boss ( Which doesn't sound all that, but it meant doing the whole "Warning" text stuff which took a while to design nicely ).

We're currently up to 5 levels done out of 12, which is pretty good going. Also quite a bit of time has been spent on the Android version, the control mode is finally nailed in that now, it plays much better than I'd have hoped and we're not sacrificing too much visually ( Less particles, fewer use of blendModes etc. but in terms of gameplay it's exactly the same ).

I also checked how my phone, HTC Desire S, performs in comparison to other Android devices, and it seems pretty poorly actually ( Not that you can tell from the phone itself, it's silky smooth ), which is good news as the game isn't dropping too many frames on it. Anyone with a newer phone / tablet should get a really good 30fps experience with it.

And before this turns into an advert rather than a dev update I'll wish you a fond farewell until next time.

Squize.

PS. Outpost:Swarm should be gold, or near as damn it, we're hoping for final feedback this Friday, so hopefully some news about that soon.

14. March 2012 18:02 by Squize

I was in two minds about posting this, the past week or so have all been about Outpost:Swarm so DN8:Pulse hasn't progressed much, but I've had a stupidly productive day today so take my hand as we talk about new things.

As you can see baddie bullets are in now. They didn't take long at all as I'm lifting so much code from the original DN8 its almost obscene. To test how well the game copes I just get each baddie shooting a bullet every frame, and even with all those bullets with a blendMode we're not dropping a frame. Nice.

I added the floating points to the game the other day, updated the skybox to make it more colourful, altered the baddie explosion particles ( I spent hours on Friday doing that, and the end result was just dog shit, I mean really bad, so I ripped it all out and started again ). Last night that little planet in the background you can see there gained a ring ( A sphere with it's z scale set to 0.1, then rotated around ).

Today after the baddie bullets I've been working on the level progression code, and it's nearly there, and to celebrate I nailed down level 1's attack waves, so that level is officially done. It's amazing how one good days coding can give you a real lift.

And I think that's enough for Pulse this week, more soon...

Squize.

GYW on the web ...

Even more of GYW ...
GYW Homepage +GYW GYW on Facebook GYW on Twitter nGFX on Twitter

Month List