- Home /
Fixed movement air jumping and ledges
I have the character set to lose movement controls while in the air, but I've run into an awkward problem that makes it hard to get on platforms. When I jump next to a platform, it's just straight vertical meaning I have to step back to jump again
https://youtu.be/WmDgzRucGUw
I am trying to get it to work more like Castlevania on Nes where you still have your x vector while at the height of the jump so getting onto platforms works when you are right next to them.
https://youtu.be/wQrmF3-YWYA
public void Move(float move, bool crouch, bool jump)
{
if (grounded || airControl)
{
Vector3 targetVelocity = new Vector2(move * 10f, m_Rigidbody2D.velocity.y);
m_Rigidbody2D.velocity = Vector3.SmoothDamp(m_Rigidbody2D.velocity, targetVelocity, ref m_Velocity, m_MovementSmoothing);
}
if (grounded && jump)
{
grounded = false;
m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
}
{
Testing a bit more, the momentum is ending the moment I hit a wall, even if the head hits the bottom of a platform. So I need to figure out a way to continue keeping that momentum regardless of the wall
Answer by Eno-Khaon · Jul 31, 2019 at 06:29 AM
To make the movement scheme more like Castlevania's, your horizontal speed needs to be tracked closely based on your input and applied when needed.
You're doing exactly that, so this will actually be quite simple.
All you need to do is process your Rigidbody's velocity regardless of whether your character would have control. Specifically, where your function's move value is the current speed you're applying, you'll want to feed the last value you tried to move at the entire time you're in the air.
If you're on the ground, read the controls for movement. If you're in the air, use the last value you had read while on the ground.
To note, this approach only really works effectively because you're modifying velocity directly.
So I'd have to capture the variable at the moment of the jump and feed it into the x value of the vector? How would I capture the variable at that exact moment then?