GMS 2.3+ 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 :)
 
Top