Looking for help locking character movement to a retro 8 direction setup

So I’m looking to create a spiritual successor to the Crusader games from the mid 90s (No Remorse and No Regret). So far I’ve gotten almost everything figured out except for the 8 directional movement of the player and enemies. Because I also need to allow for full rotation of the character for combat while not moving, I “think” what I need to do is divide the full 360 around the character into 45 degree partitions and when attempting to walk forward (Forward and Backward are the only directions a player can move in) check the degree measurement and then adjust the forward motion to the nearest 45 degree line.

The problem is, I have NO clue how the heck I’m going to accomplish this as I don’t know how to do the initial setup of specifying the degree segments.

Any help with this would be greatly appreciated. I’ve been banging my head against a wall on this for a few days and every time I think I may have something, it turns out to be a failure in addition to breaking something else that is already working.

Here is what I’m working with on the movement side:

Thanks for the idea, Chyros. I’ll give that a shot tonight when I get some time and let you know how it goes.

This really helped me a LOT and I really appreciate it! I was able to modify this to put in all of the restrictions I wanted!

Now I just need to figure out how to increase the rotation speed since it’s very slow.

And apparently I need to figure out how to mark a comment that isn’t mine as an answer.

So I realized today that what I wrote wasn’t exactly what I was looking for. I could blame it on being dead tired but that just means I should have waited to post my question.

What I’m really looking to do is have forward / backward movement only and have it constrained to only functioning along the 8 directions by dividing a full 360 into 8 45 degree sections. I want to allow full rotation for aiming but to snap to one of these preset directions based on which 45 degree line is the closest.

I have the movement confined to forward and backward, the full rotation, and what I think is the correct way of setting up the auto-rotation; but when I try to do the rotation and then move forward when the player attempts to walk, it will snap to the correct line and move but the model will rotate like crazy when moving along that line, even though the movement is locked to that line until stopping and rotating.

I’ve added the section in this screenshot to allow for the rotation but it can’t figure out how to trigger it so that it executes once upon triggering move forward / backward and then allow the player to keep moving without triggering this on every tick. I’m thinking I’ll need to use a Do Once?

Ah the Resident Evil-classic / Desert Strike movement-style type. Here’s what I did on mine:

First setup your character:

  • Uncheck UseControlRotationYaw in CharacterBP

  • Uncheck OrientRotationToMovement in CharacterMovementComponent

  • Create a Yaw float variable that keeps track of current Character rotation

  1. Create UpdateYaw event that updates Yaw variable and constraint if to -180 to 180

  1. Actual rotation based using MoveRight key

  1. Move Forward/Backward based on current rotation

When you hold A or D keys (MoveRight), you’ll see him snap to 8-way direction. You need to update it to make it more responsive just like in Crusader but that should get you started. I’ll try update this as soon I returned from work.

Your Yaw variable still keeps track of the full rotation range from -180 to 180 so you can still probably use it for your aiming. Your character rotation only updates when your Yaw is divisible by 45.

You’re welcome. I made the comment as answer so you can mark it as one if you want.

As for the rotation speed, you can increase the AxisValue by 45 but you have to do some changes because the MoveRight event will spam the event with multiples of 45 making the rotation too fast. Either use 45 in Axis Value and use a Gate node to throttle the event calls when holding the Left or Right keys. Or, you can just increase the AxisValue by multiplying it with 2.0 or so and everything remains the same.

I’ll try something later on when I get home from work and see how we can improve the responsiveness.

Just a quick note, I noticed I made a mistake on the UpdateYaw event.

From:

if Yaw > 180, then set Yaw = -180

Should be:

if Yaw > 180, then set Yaw = Yaw - 360

And then:

if Yaw < -180, then set Yaw = 180

Should be:

if Yaw < -180, then set Yaw = Yaw + 360

Shouldn’t made much difference with small increments/decements in Yaw but will probably have problems when incrementing and decrementing with larger values.

This is great, you’ve really helped me out here and I greatly appreciate it!

So I’ve made some adjustments to try to fix the 45 degree rotation jumping but it’s not working. Do you have idea why it wouldn’t work in this case?

From what I have here, it looks like it should update the rotation as normal so long as the character is not in the air and the MoveForward axis is = 0. But when the MoveForward axis isn’t 0 and the Crouch button isn’t being held down, then it would check to see if the current Yaw value is a multiple of 45. If it is, start moving, if it isn’t, round the Yaw to the nearest multiple of 45, rotate the character to match then and then move.

For the Life of me I can’t see anything wrong, however, if I left my old code in but completely disconnected, the rotation works but ignores the multiple of 45 degrees check?!?! Beyond frustrating!

As you can see, there aren’t any actual events being called and nothing “should” be getting triggered from this.

I tried your blueprint except the Crouching part. Here’s what happens on my end:

  1. If not in air and not moving forward/backward, rotation works without snapping.
  2. If I start moving forward/backward, rotation is updated to the nearest 45 degree and then moves forward/backward

What is not working in this case?

Also, if you haven’t tried Blueprint Debugging, it would make it easier to know which nodes are being executed and what values the variables has.

Yeah that happens to me too. When something is not working where I think it should happen correctly, i do the “Microsoft Solution” all the time - which is to restart application.

Apparently nothing. I killed the engine and re-launched it and it started working perfectly. So frustrating when that happens. Haven’t run into it since 4.9.