• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM What is the best way to create “kickback” when running into object?

For context, I am creating locks and keys to portals (which move you from one room to another) and when someone doesn’t have a key, I want them to be pushed back and given a message. I have already gotten it to display the message, but I don’t know how I would create kickback (both for when it is jumped on and when ran into). I should also mention that I’m trying to do this with code and not the DnD options
 
Last edited:

Nocturne

Friendly Tyrant
Forum Staff
Admin
In general, and not just in this case, you want to set up a "finite state machine" for the player character, and in that you would have a "kickback" state where you could then hard code some movement into the player object that throws them back while ignoring user input. If you are unfamiliar with the concept, here's a very simple tutorial I created some time ago about FSM: https://www.yoyogames.com/en/blog/coffee-break-tutorial-finite-state-machines-gml

Here's a video from Shaun Spalding too that explores the idea:

So, basically, you split all your player actions into "states", running, jumping, falling, kickback, etc... and then code each state individually and switch between them as required.

Hope that helps! :)
 
In general, and not just in this case, you want to set up a "finite state machine" for the player character, and in that you would have a "kickback" state where you could then hard code some movement into the player object that throws them back while ignoring user input. If you are unfamiliar with the concept, here's a very simple tutorial I created some time ago about FSM: https://www.yoyogames.com/en/blog/coffee-break-tutorial-finite-state-machines-gml

Here's a video from Shaun Spalding too that explores the idea:

So, basically, you split all your player actions into "states", running, jumping, falling, kickback, etc... and then code each state individually and switch between them as required.

Hope that helps! :)
How exactly do I create a state in which if they have a key they get knocked back but if they don’t then they unlock the lock? I suppose that I could use an if statement like
GML:
if (keys>0) {
    with other {
        instance_change (obj_portal, true)
        }
    keys = keys-1;
} else {

state.kickback
}
Or something along those lines? But how would I make that only happen when the two objects collide? Would I need a whole other script for when the player collides with the lock?
 
Last edited:
Top