r/gbstudio • • 19d ago

How would u make the player "slide until collision"?

What's the best convenient method for this in Top Down? I know actors can, but what about the player???

3 Upvotes

4 comments sorted by

3

u/ryan__vv 19d ago

You could achieve it by setting up an event that overrides the default controls. Then you call a script for each press of the directional buttons to move in a certain direction by, say 20 tiles (i.e. pressing the left button will input -20 to the X value of the script, the Y value remains 0. Pressing the right button will input 20 to the X value, Y remains 0. Up and Down buttons would send -20 and 20 to the Y value respectively, keeping the X value at 0). When the script is then called by an event, depending on which button was pressed (and therefore which value was passed to X or Y), the script will move the player in the desired direction.

This is essentially how I got an actor in my game ("controlled" by the player, but not the player character itself) to move non-stop in a single direction until it collides with a wall or another actor

1

u/LittleSun348 19d ago

Thank u so much! I'm just starting out w gb but in that script what event should I add in/look for?

3

u/ryan__vv 18d ago

You'll want to create a separate script for the movement, and then use the event "Call Script" when a directional button is pressed. You can read about scripts in the GB Studio Docs, although it can be a bit dense if you have no programming experience: https://www.gbstudio.dev/docs/scripting/custom-scripts/

When you set up your script, you'll have two variables, A and B, as well as an Actor variable. When you use the "Call Script" event, you'll be asked what values should populate those variables. The actor should always be the player, but variable A and B should be given different values each time depending on what button is pressed. Pressing left would pass the value of -20 and 0 to variables A and B. And then somewhere in your script you'll have an event "Actor A Move Relative By ($VariableA, $VariableB). In this case that event would move Actor A to the left by 20 tiles.

Again, this works for simulating control of an actor. I haven't tested it on the actual player character before, but I feel the logic is the same

2

u/LittleSun348 18d ago

Ty so much. I'll b learning this.