Hello, I am currently making my first project and I have reached an obstacle I can’t fix.
I am making a puzzle game where the goal is to reach the end in as few moves as possible, but at the moment I can simply move around my pawn until I reach the end, which defeats the purpose.
I want my pawn to only move in four directions, and slide all the way until it hits a wall before I can move it again.
I have made two short clips of how I want it to be and how it currently is.
Hey there @LindbergNGS! Welcome to the community! There’s actually so many ways to do this, and yours isn’t actually very far off from a basic implementation.
So the best way to get to developing the correct solution is to design the solution first.
Let’s look at what we want to accomplish.
We need the player to move vertically and horizontally but not at the same time
We need the player’s collision not to cut through the wall.
We need the player not to rotate at all.
So now we can determine how to do these things efficiently.
First we’ll address movement. This is rather important to get right as you don’t want to fly out of the map like you do. The sweep is to make sure it doesn’t try to push into the walls and flip out.
I believe this solved 99% of the problems I was having with the movements for my pawn. There is however one little detail in the movement I would still like to add to not make it so simple to reach the end of the puzzles.
When I press right for example, I want my pawn to go all the way to the right which makes it impossible for me to stay in between the obstacles to then slightly move freely around the board. Think of it as if my pawn was on ice, with no ability to stop until it hits a wall.
I tried increasing the multiplier a lot to make it impossible to stop in-between objects, but it is not perfect.
The goal in that puzzle is to reach the middle of the map, and as you can see it is not possible to simply stop in the middle of the movements to make a quick turn.
Hopefully you can understand what I am trying to explain with the ice floor.
Definitely should have the floor mesh isolated and put it in a different collision channel so you can then specify not to make contact with it ever. Or even better, since the floor is just decoration, if you never need it to collide with anything you could just remove it’s collision altogether. That said you would still have to edit the box so the floor is not a part of the walls and internal bricks.
Another, completely different solution is not to use pawn movement at all. No movement = nothing to interrupt
when a key is hit and direction established, trace until you hit something
now you have start & end points, measure the distance to calculate timeline play ratio
use the timeline to Lerp between start & end
This is quite efficient as it would require a minimalistic setup regarding collision, it also does not tick. It’s not the best choice if you’re planning on having moving / dynamic obstacles, though. On the other hand, a TL would give you plenty of control of the curve so you could setup something advanced quite rapidly.