Improving The Jump in 3rd Person Controller Course

I put that into my Jumping and Falling states and it solved the problem of my character turning to world front while jumping.

Unfortauntely (i think this was also an issue before) if I turn while in midair and let go of the input, my character faces world front.

I get these messages anytime the character abruptly turns to world front.

Same problem. All calls to look in a direction need to be “null checked”… or more to the point, Zero Vector checked.

Interesting, I thought it would be checking for it all the time because it’s in the Tick method.

I tried both

if(momentum.magnitude > 0.05f) FaceMovementDirection(movement, deltaTime);

and

if(momentum.magnitude > 0.05f) { FaceMovementDirection(movement, deltaTime); }
and they didn’t seem to make a difference.

You’re checking momentum, and facing movement…

1 Like

Can’t believe I missed that. Turns out switching to

if(movement.magnitude > 0.05f) { FaceMovementDirection(movement, deltaTime); }

worked.

Now to solve the issue of my character refusing to midair adjust in the direction they’re facing if they’re facing anywhere other than camera front.

5 demerits for Ravenclaw

Make sure you’re using stateMachine.transform.forward and stateMachine.transform.right, not stateMachine.camera.transform.forward/right…

When I put

protected Vector3 CalculateAirMovement()
    {
        Vector3 forward = stateMachine.transform.forward;
        Vector3 right = stateMachine.transform.right;
        forward.y = 0f;
        right.y = 0f;
        forward.Normalize();
        right.Normalize();
        momentum += (forward * stateMachine.InputReader.MovementValue.y + right * stateMachine.InputReader.MovementValue.x) * stateMachine.JumpSteeringStrength;
        return momentum;
    }

and set my JumpSteeringStrength to 0.05, I get the same results as before.

I did find a quick band-aid solution, it’s not perfect (the jumps cover less distance and feel less natural when I do it this way) but it works for now. I made my Falling and Jumping Tick methods look like this.

public override void Tick(float deltaTime)
    {
        Vector3 movement = CalculateMovement();
        Move(movement * stateMachine.FreeLookMovementSpeed, deltaTime);
        momentum = ApplyInputToMomentum(momentum, deltaTime);
        
        if(movement.magnitude > 0.05f)
        {
            FaceMovementDirection(movement, deltaTime);
        }

        if(stateMachine.Controller.velocity.y <= 0)
        {
            stateMachine.SwitchState(new PlayerFallingState(stateMachine));
            return;
        }
    }

If I could accomplish this but by using momentum in my Move (momentum, deltaTime); that would be perfect.

Update:

I added Vector3 momentum = CalculateAirMovement(); to my Tick as to try and make use of the momentum = ApplyInputToMomentum(momentum, deltaTime);

Things seem to flow better but it’s hard to tell at the moment.

5 points from Ravenclaw. Move’s responsibility is to move, adjust momentum outside of Move.

10 points to Ravenclaw, well done!

1 Like

So far it seems to work the way I want it to. Will have to refine and refactor later but this was a huge step forward. Thank you so much for helping me through yet another issue.

At the moment, I’ve got to figure out how to fix the bugs that occur when my player jumps on top of enemies.

That’s something I haven’t worked out yet, either. It’s on my list…

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms