- Home /
Smooth walljumping
Hi everyone
So a friend an I are making a 2.5d platformer game. One of the most important aspects of our game would be walljumping, sliding, climbing, etc.
Now, I started implementing a walljump mechanism in my movement script. I'm using the CharacterController.
The problem I encounter is that my character does not jump away from the wall, even though I'm applying a vertical and horizontal velocity. This is likely caused by my other code of moving horizontally.
Below you can find my walljumping code:
if (_canWallJump && !_cc.isGrounded)
{
moveDirection.y = jumpSpeed;
if (_hitDirection == HitDirection.Left) moveDirection.x = -jumpSpeed;
else if (_hitDirection == HitDirection.Right) moveDirection.x = jumpSpeed;
_timeOfWalljump = DateTime.Now;
}
This is my horizontal movement code. Note that I already tried implementing a fix, by ignoring the horizontal input for half a second, I hoped to get some nice jumps, but to no avail.
_dx = (DateTime.Now - _timeOfWalljump).TotalMilliseconds >= _millisecondsToIgnore ?
Input.GetAxis("Horizontal") * speed :
_dx = moveDirection.x;
moveDirection = new Vector3(_dx, _cc.velocity.y, 0);
I was hoping that some of you could help me fix it or provide some code examples on how to do it properly.