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.

DarkBASIC Professional Discussion / Steering behaviours for DBPro - a New Year's present from everyone's favourite Bear

Author
Message
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:36 Edited at: 2nd Jan 2006 22:23
A few months ago I did a bit of ranting about autonomous steering and, in particular, Craig Reynolds' seminal work in the area. For those who could do with a quick recap, here's my thread: http://forum.thegamecreators.com/?m=forum_view&t=63819&b=1
and here's Craig's website: http://www.red3d.com/cwr/steer/

I subsequently did a bit more ranting at the DBPro Con and passed around Mat Buckland's excellent book: "Programming Game AI by example" http://www.amazon.co.uk/exec/obidos/ASIN/1556220782/ref=pd_sim_b_dp_1/202-4091667-6122265

The object of all this ranting was twofold: (1) to persuade someone else to buy me a beer to shut me up; and (2) to persuade someone else who has more time than I to convert the major steering behaviours into DBPro code.

Well, I failed to persuade anyone of either. So, being officially the forum's most helpful bear, I've spent that part of my Xmas holiday not devoted to drinking beer and scoffing mince pies in converting the most important steering behaviours into nice simple DBPro examples for everyone.

Hence this thread. You'll find below a series of nice DBPro snippets demonstrating each behaviour in turn. I've started as simply as possible and then, as you'll see, have started to bolt stuff on. For example, in the first new snippets the main cube only moves position but not orientation - later orientation changes as well. As an added twist, I've taken Craig and Mat's examples and turned them from 2D into 3D.

The nice thing about these behaviours is that they encapsulate a lot of the key issues often raised by hobbyists, i.e. time slicing, how to incorporate basic physics into movement (such as mass, acceleration and inertia), etc. Play around with these variables and see what I mean.

All examples are written using DBPro v5.9 and the latter ones require WOLF's EZrotate (and, in a few cases, Cloggy's D3D plugin). All examples have comments in the code. If you want to understand exactly how they work, you'll need to have an understanding of 3d vector maths.

Enjoy.

Philip

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:36
This is seek:



Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:37
Flee, being the opposite of seek:



Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:38
Arrive, a more sophisticated version of Seek:



Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:39
Wander:



Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:40
Pursuit:



Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:40
Evade, the opposite of Pursuit:



Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 00:44
Obstacle avoidance:



Incidentally, you'll see that the cube "detects" various obstacles that don't not apparently fall within its detection box. This is because, as you'll see from my maths above, that the actual detection box is bigger than that represented on screen. The reason for this is that there is a margin for error.

Plus, sometimes the cube doesn't avoid a particular obstacle. This is because of my relatively weak settings for the obstacle avoidance force. A bit of playing with those variables produces a huge range of results from massively paranoid obstacle avoidance to shaving the sides off the obstacle.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Hawkeye
20
Years of Service
User Offline
Joined: 19th Sep 2003
Location: SC, USA
Posted: 2nd Jan 2006 01:23
Coooooooool... this'll come in handy, to be sure

*bookmarks page*


I am but mad north north-west; when the wind is southerly I know a hawk from a handsaw - Hamlet, Hamlet
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 2nd Jan 2006 01:29
He knows how to give value for money

Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 01:41
I should perhaps have also mentioned that the d3d plugin generated 3d line in the obstacle avoidance example doesn't display properly if you keep my camera 1 (chase camera) code included. This seems to be a bug with the d3d plugin. If you take all the camera 1 code out, it'll work correctly again. Nothing else that I can do to fix this I'm afraid.

Oh, and I've got an example of offset pursuit up and running. This is used in, for example, creating convoys or wingmen, etc. etc. I'll finish this and post it tomorrow.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
pinball
18
Years of Service
User Offline
Joined: 31st Aug 2005
Location: Colorado Springs
Posted: 2nd Jan 2006 01:43
This will be very helpful to me

huh?
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 20:38 Edited at: 2nd Jan 2006 20:39
As promised, here is my Offset Pursuit:



NB: As the extensive comments in the code explain, in an attempt to simplify this as much as possible, I've left all the interesting technical stuff for the pursuing blue cubes. The "leader" green cube is just going around in a circle via pythagorean maths. Hence its not an instance of the obj type and doesn't have any velocity vectors or other attributes of the pursuing blue cubes.

This means I've had to use a quick hack for the leader's speed and its velocity. As my comments in the code explain, ideally your leader would also be an instance of the obj type and so you would be calculating its speed and velocity vector each turn using the update_vehicle() function. You would then replace the two quick hacks in the behaviour_offset_pursuit() function by the leader's speed and its velocity where indicated by my comments.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 21:37
... oh, and lets not forget - Interpose:



In this example, the blue cube tries to reach the midpoint between the two green cubes, adjusted of course for time and future positions.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 2nd Jan 2006 22:02
I had a conversation with David T a few weeks ago, and decided you might have bought Lua to try and do this steerage stuff. I knew it was a bee in your knickers you just needed to get out

Nice work, bookmarked.

Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 22:21 Edited at: 2nd Jan 2006 22:24
The great thing about the basic behaviours is that you can use them to create much more interesting and complex behaviours.

For example, here is continuous Path Following using the Seek behaviour (I find this example very hypnotic to watch. Be careful! Health warning - do not compile this example if you don't want to be staring at boxes moving around the screen for ages):



You need to be v. mindful of the effect of inertia when using Seek. Hence using too large a mass/acceleration ratio for each green cube gives very inaccurate results (try it and see what I mean). For smoother movement, replacing Seek with Arrive works better.

Incidentally, for some reason the update_heading() function makes the green cubes vanish. There is no mathematical reason for this (as all that function does is rotate the object) and there are no hide object or delete object commands being used. I suspect a bug with either DBPro or, more likely, in the D3D plugin. I'm going to refer this to Mike to see what he thinks.

I love all these steering behaviours. Tis a great application of vector maths.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 2nd Jan 2006 23:06
@BatVink

Whoops, almost missed your post there. Actually, I didn't buy Unity for the steering behaviour. I'm going to be using Unity for the purpose of scripting cutscenes and also to run the finite state machine that runs the AI in my game. Its v. good - DavidT has done a great job with it.

@Back to the regular scheduled steering programme

As a further example of increasing the complexity of behaviours, here is Wandering with Separation:



In other words, its just 30 cubes Wandering as normal, except that they try and stay outside the separation_distance from each other.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 3rd Jan 2006 00:20
... and finally, Wandering with an experimental form of Flocking (a system of emergent behaviour made up of Separation, Alignment and Cohesion, as defined by Craig Reynolds):



I say "experimental" because I'm not entirely satisfied with Separation. However, thats now it from me on this topic - I won't be posting any further steering behaviours, mostly because I can't think of any.

Thats All Folks.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Philip
20
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 12th Feb 2006 16:04
BatVink, do you mind sticking this entire thread into Tutorial City? Ta.

Cheer if you like bears! Cheer if you like jam sandwiches!
RiiDii: "I highly recommend Philip's vector tutorials"
P3.2ghz / 1 gig / GeForce FX 5900 128meg / WinXP home
Chris Franklin
18
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 12th Feb 2006 16:11
Very cool

Theme park simulator 15% Currently making object selection

Login to post a reply

Server time is: 2024-04-16 15:24:53
Your offset time is: 2024-04-16 15:24:53