How do I get a 4-way linear movement with a slide?

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.

This is how I want it to be: How I want it to be - YouTube

and this is the current situation: The mess it currently is.. - YouTube

How would I change this movement in blueprint?

I understand my current blueprint is wrong here, but I have no clue how to resolve it so it matches what I want.

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.

Also need to set your root’s Constraints so you don’t have to worry about it bouncing around.

Also gravity is not a good idea.

And Voila can only move one direction at once, I iterated on the way you built yours so it should be adaptable.

2022-08-20_21-01-54

Let me know if you have any questions!
Also the BP in the BP site: blueprintUE | PasteBin For Unreal Engine

A thousand thanks to you!

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.

I got the inspiration for my little game from this puzzle shown here at 3m55s (The audio is quite loud, so beware) Castlevania Lords of Shadow Reverie DLC Chapter 13-3 Founders’ Quarters (pt.3of5) - YouTube

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.

Thank you again for the help.

Try this:

This will allow you to change direction only once the pawn has bumped into something.

I tried doing this but my pawn seems to lag and hit the floor.

I think I made a mistake when I made the whole puzzle board into a static mesh which causes my pawn to always bump into something.

I tried making my pawn float up in the air so it would not touch the floor, but I can still move it around a bit whenever I want.

You can isolate it with collision channels. Have the pawn ignore the floor.

I was unable to interrupt the movement with the above script.

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 :innocent:

  • 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.

1 Like