+1 vote

I'm just trying to make one of those sliding block puzzles but instead of pushing a block, you press a direction and then your character slides in that direction until it hits a wall. I'm new to coding and know nothing about the language so I rely on tutorials but there's none for sliding block puzzles apparently. If you could respond with a code and explanation of the code, that'd be appreciated!

in Engine by (13 points)

2 Answers

+1 vote

Broadly speaking, you have two options.

  1. Rely on physics. Create your blocks with collision shapes. Use TileMap to help with level creation and set certain types of tiles as blocking. When the player moves into a block, apply a force to it and then fine tune the details. (Magnitude, friction, etc.)
    https://docs.godotengine.org/en/stable/tutorials/physics/physics_introduction.html

  2. Handle the game logic separately from the visual representation in a grid matrix of some type and use the engine to render visuals. This method will give you total control over the logic, but it may be a bigger challenge to get animations working correctly, especially if you plan to have pushing a block create a chain reaction.

by (856 points)
0 votes

https://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html#class-kinematicbody2d-method-move-and-collide

moveandcollide can: move your player, stop your player when it collides with something, and return what was collided with.

example project files

https://files.catbox.moe/dh4m7l.zip

Hope this helps. Have fun with Godot Engine :D

by (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.