Best way to implement Megaman X style movement

Hi everybody!

I’m new to UE4 and I find myself struggling to implement a Megaman X style movement for my character. That movement consists on:

  • character can walk in 2d
  • can control the height of the jump (the longer the button press, the higher the jump)
  • can dash sideways (grounded or in air)
  • can wall jump

I can see several ways to achieving this:

1- Start from side scroller template and add code on top of the template character
2- Override CharacterMovementComponent and change its behaviour
3- Start from an empty pawn the do all the movement from scratch
4- Start from an empty pawn with physics and apply forces

In my past experience developing games, I would do number 4 and create all the movement on a physical object, but in ue4 this does not seen to be the best aproach.

For ue4 I think number 1 or 2 to be the best options, but 1 is everything premade, so to implement jump height control I found myself getting into number 2.
To change CharacterMovementComponent behaviour need some quite good undertanding on how it works by reading the source code. So I’ve tried number3.

In 3, if I added charactermovement I would go back to 2. So how can I move it with collision detection?
I found AddActorLocalOffset , it do almost right, but it stops completely on collision, so the character can’t move on slopes.

In 4 I would have full control of movements with collision. But I found that I can’t disable friction nor change my mass to the value I want (without geting changed by the volume). I think I can lock rotations on X and Y axes on code, but I don’t know if there is a right way to do it. I got the feeling that physics in ue4 are intended to be used on props and obstacles, not for gameplay implementation.

Well that is my initial thoughts. Have I missed something?
I have no problem with c++ or blueprints. I just would like some orientation on the best way to do things in ue4. How would be your aproach?

Thankss!!

The interesting thing about C++ and well programming in general is there really isn’t a set way of reaching the gold. 1+3 = 4 & 2 + 2 = 4 & 5 - 1 = 4. Lots of ways to get there! But i’m sure you already know that.

How would I handle this… hrm. Well, I am definitely more of a C++ guy then blue-prints so i’d definitely handle it via code. Just feels much more natural to me that way. I’d start with the side-scroller and just modify certain things, it’d be the best place to start. I’d use timers to indicate the power of a jump which in turn would increase the height depending on how long it was held.

GetWorldTimerManager().SetTimer(…), ect.

As for the dashing i’d probably use a timer for that as well with the movement keys to determine if I had just pressed it or not this way I can give as much time in between as I would like. And for the wall jump, i’d detect a collision if true then when I press the jump key again play the jump animation and rotate the character in the opposite direction.

Thanks Master Kyp for the help!

In the end I opted for using number 1, it seens the most straightfoward for someone who newbie in ue4.
I just found that the feature do hold to jump higher was included in the 4.2 update, so that is not a problem anymore.
The wall jump I’m doing almost like you said, with on ReceiveHit , jumping on -HitNormal , but I used CharacterMovement->Launch instead of jump, because I didn’t found how to tell character that it can jump again.

As for dashing, I used the timer as you said combined with Launch.

A still have some problems with the character rotation, when I relese the right or left button while the character is turning, it can stop facing the screen instead of sideways. How can I solve that?

CanJump() under ACharacter is what you’re looking for pal. Though it looks like you’re getting the hang of things. Glad I could help.

What you could do for the rotation is literally make a condition. If(MovementKeyRight_held != 1) Set Rotation. Meaning, everytime you let go of the movement key rotate him into the last direction that was held.

Too be fair there is actually a number of ways of handling this… but it can depend on the art-style that you’re going with. You could handle it like Donkey Kong Country and just ignore rotating all together. Or you could just handle it via animation.

We are hoping that the character movement code that comes with the engine is a great starting point for a lot of different games, because it can be such a tricky thing to get right (and make work well in network play). We are continuing to make it more flexible, check out this recent blog post for example:

If you have any more suggestions on things that things that you are trying to do but finding tricky, please let us know!