unity – What’s unsuitable with this floor test in my HSM?


I am engaged on a 3rd particular person platformer. The participant controller makes use of a hierarchical state machine taken from this video : https://www.youtube.com/watch?v=OtUKsjPWzO8

Utilizing Unity 6.0.

At the moment, it is arrange so that there’s a central state (MBaseGameplayState) which derives into two broader common states (MStateGenAirborne, MStateGenGrounded) which then break up into extra particular states (strolling, falling, leaping and so on…) I’ve positioned the logic for calculating whether or not it is grounded within the central state in order that I haven’t got to rewrite it for every class. This state additionally handles motion, and every of the lessons that put it to use to switch the motion values to get the motion i am on the lookout for (drag, velocity and so on.)

// MBaseGameplayState

public override void FixedUpdateState()
{
    base.FixedUpdateState();

    // grounded test
    if (Physics.Raycast(_mPlayerSM._rb.rework.place, Vector3.down, .6f, LayerMask.GetMask("Floor")) == true && _mPlayerSM._rb.linearVelocity.y <= 0f)
    {
        _grounded = true;
    }
    else
        _grounded = false;

  ...

The difficulty begins with the leaping state. It provides a vertical drive to the participant rigidbody and switches to the falling state when the yVel of the rb is <= 0. Whereas it does add the drive, evidently at some stage in the soar, it reads that the speed is = 0, thus switching to the falling state, which then instantly switches to the idle (grounded) state, as a result of at some stage in the soar it is also learn the raycast as being grounded too. This all occurs in the identical body the soar button is pressed from the grounded (MStateGenGrounded) state.

Even when strolling round, the rb velocity reads as 0, regardless that it is shifting by including drive to it. Surprisingly, when a line is added to the StateMachine’s replace operate simply to serialize the rb’s velocity, it begins to alter the values, however breaks the motion.

I’ve tried including empty override FixedUpdateStates to every of the associated lessons (possibly they weren’t being up to date/referred to as?) however no no avail. I’ve additionally tried including stricter conditionals for switching states, however that does not appear to be the problem.

Very confused as to what the problem could possibly be… Assistance is appreciated 🙂

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles