Vectors and Steering Behaviors

samspade

Member
GM Version: 2.3.1
Target Platform: All
Download: Github Repo for Vectors and Steering Behaviors
Links: YouTube Video Playlist

Summary
A tutorial series cover a basic implementation of vectors in GameMaker Studio 2.3 and Steering Behaviors. A link to the playlist and the github repo are above, and an outline and first video are below.

Outline

Intro to Vectors

Intro to Steering Behaviors
 
Last edited:
I'm really loving this series.
My game is a single screen arena shooter and I've got a particular enemy that will run from the player if the players shield is active, but I'm stuck trying to figure out how to stop them leaving the screen. There is are walls around the edge which I would like them to try and escape rather than just stopping at the wall. Any pointers would be appreciated.
 

samspade

Member
I'm really loving this series.
My game is a single screen arena shooter and I've got a particular enemy that will run from the player if the players shield is active, but I'm stuck trying to figure out how to stop them leaving the screen. There is are walls around the edge which I would like them to try and escape rather than just stopping at the wall. Any pointers would be appreciated.
It could be worth asking this in the general programming forum and showing all the code you're using, but in general, you can use steering behaviors with the 'standard' collision script. I haven't tested it, but I believe this, or something very similar, would work for instance:

GML:
function move_and_collide() {

    //horizontal movement and collision
    if (place_meeting(position.x + velocity.x, position.y, solid_parent)) {
        while (!place_meeting(position.x + sign(velocity.x), position.y, solid_parent)) {
            position.x += sign(velocity.x);
        }
        hsp = 0;
    }
    position.x += velocity.x;

    //verticle collision and movement
    if (place_meeting(position.x, position.y + velocity.y, solid_parent)) {
        while (!place_meeting(position.x, position.y + sign(velocity.y), solid_parent)) {
            position.y += sign(velocity.y);
        }
        velocity.y = 0;
    }
    position.y += velocity.y;

}
So instead of just adding velocity to position, you would add velocity to position while checking for collisions at the same time. If leaving the room is the only thing you're trying to stop, you could also clamp position x and y to the rooms width and height. Pretty much anything you can do with an object's x and y you can do with the position x and y before updating the actual x and y.
 

kburkhart84

Firehammer Games
These have been nice so far. I'd been meaning to learn the whole steering behavior concept and these short videos certainly take care of that. Keep 'em comin :)
 

samspade

Member
Flocking behavior is up (which is really three steering behaviors combined—align, cohesion, and separation).

 

samspade

Member
Optimizing steering behaviors is up! I really don't know much about optimizing code, so I kept it basic and if someone wants to shoot for really making it as fast as possible, I'd be super interested to see what you do.

 
  • Like
Reactions: Sad

Sad

Member
I love your work, especially this series. It's heavily edited, with illustrations, snippets, slides, highlights, no annoying BGM, clear tone, the way you break the pieces into easy to digest bits. It's pretty apparent to me that you've put lot of thoughts and research before you start hitting that record button.

I prefer your format at any day, Than those other tutorials where I'd be mostly staring for the dude's meandering around IDE from start to end with occasional ramble in the middle.
 
Top