For a while now I’ve been trying implement Mario-style jump mechanics into my game such as being able to control the height of your jump by how the long the jump button is held (a.k.a. variable height jumping), and being able to take out enemies by jumping on them as well as bouncing higher off of them by holding the jump button down while doing so.
I’ve managed to work out the mechanics for the most part, but I’ve been plagued with problems of my player character occasionally taking damage while jumping on the enemy. In order to fully explain what is very likely happening, I’ll first need to explain the setup of the jumping & damage mechanics, starting first starting with the player’s hit collision:
1.) This is the collision capsule for the player character, if an enemy touches this then the player takes damage.
2.) This is jump collision box, which is actually more of a flat 2D plane rather than a box, attached directly below the collision capsule; if this box comes into contact with a vulnerable enemy then the player will bounce off the enemy’s head and the enemy will take damage, with the player bouncing much higher if the jump button is held down.
Next is the blueprint for jumping as a whole, including mechanics for variable height jumping, as well as SFX while jumping:
And this is the Jump & Bounce function which is called upon in enemy blueprints to allow the player to be able bounce higher off of an enemy by holding the jump button:
Next up is the Receive Damage portion from my player character’s blueprint. Here is where the logic for the player taking damage is set up and is connected to a custom event that can then be called upon within the enemy’s blueprint:
And lastly is the portions of the enemy blueprint related to the player taking damage from the enemy & jump collision. I thought I should also point out that the Receive Damage function targeted to the enemy is entirely separate from the Receive Damage custom event that handles damage to the player, I just didn’t bother to give the two events different names:
Sorry for the long-winded explanation but anyways, the reason that the player is taking damage when they’re not supposed to is that the player’s collision capsule is coming into contact with the enemy when it shouldn’t. The jump collision box in addition to dealing damage to the enemy is supposed to prevent this happening by bouncing the player upwards upon the jump collision box connecting with the enemy’s collision capsule.
I’ve been told somewhere else that the likely culprit behind this glitch is irregularities in tick timing, which I suspected might be the issue as I noticed that putting space between the jump collision box & the collision capsule appears to reduce the frequency at which the player takes damage from jumping on the enemy.
To remedy this problem, I tried to number of things that were recommended to me such as adding a brief period of invulnerability for the player when jumping on the enemy and enabling Continuous Collision Detection (CCD) on the player’s collision capsule. Adding the brief invulnerability period did help a bit, it hasn’t completely fixed the problem, while Continuous Collision Detection’s effectiveness isn’t really obvious.
Also likely tied to this problem is another glitch I’ve been experiencing where if I press the jump button in rapid succession while bouncing on an enemy results in the player bouncing rapidly in a manner that shouldn’t be happening. The reason I suspect this glitch is related to the other one is because I’ve noticed that the player is far more likely to take damage while the jump button is being held down. This particular glitch is almost definitely the result of the Launch Character node that is used to control the jump height of the player character when the jump button is released. I’ve been told elsewhere that this node is very likely a major contributor to the irregular tick timing issue and should be replaced by something else.
The problem with this though, is that I don’t know what else I could replace the Launch Character node with. Unreal Engine 4’s built-in Stop Jumping event doesn’t cancel the player’s jump when the jump button is released, while other solutions I’ve seen involving playing around with gravity & using timelines go way over my head and so I’m unable to implement these solutions myself.
I was also recommended to increase the “Position Solver Iteration Count” but I’m rather hesitant to play around with values I don’t understand what their function is.
So does anyone know how I can control the height of my player character’s jump by how long the jump button is held down without the use of the Launch Character node? Or any other methods of how I can better optimize my setup so that the player character no longer takes any damage from jumping on an enemy?
Any help with this matter would be greatly appreciated!