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.

AppGameKit Classic Chat / 2D Vector library (with Seek/Evade steering behaviour usage example)

Author
Message
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 11th Jul 2021 10:00 Edited at: 11th Jul 2021 10:02
Below is my 2D Vector Library which you can #include in your own code. And attached is a usage example using seek and evade steering behaviours as described in Craig Reynold's research paper on on autonomous agents.
In the usage example, the 'target' sprite seeks a random waypoint. When it finds it, it will choose another waypoint and steer/accelerate towards that and so on...
The 'enemy' sprite will seek the player unless they get too close and then then will evade it instead.
Any enemies that collide with the target will be respawned in a random location and continue as before.


Attachments

Login to view attachments
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 11th Jul 2021 16:45
Nice example, I like the flocking effect.

This is also handy for 3D if one swaps the y and z, for schools of fish and birds ETC at a set height.

Thanks for sharing.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 13th Jul 2021 08:59
For anyone that would like to learn more about vectors and how they work, I would very much recommend watching some of Daniel Shiffman's videos on YouTube. He is quite eccentric but incredibly informative. His website and link to his videos can be found here: https://thecodingtrain.com/learning/nature-of-code/
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Jul 2021 03:59
Glancing at his videos, I've always handled it differently. I maintain a normalized direction vector and keep velocity and acceleration as scalars, just seems easier to work with that way.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 14th Jul 2021 10:40
I know what you mean. I used to do the same but my inner pedant has to point out that velocity must be a vector because it has direction and magnitude. Speed could be a scaler. But like I say, I'm just being pedantic, if it works then go with whatever system you prefer.

Login to post a reply

Server time is: 2024-04-20 10:04:57
Your offset time is: 2024-04-20 10:04:57