stateMachine.Controller.Move causes the player to "pop up"

Hello,

First post to the forum here. I’ve been trying to track down a bug in my Third Person Unity code base (the course is excellent by the way :). I’m on the Weapon Knockback section - and i found an odd intermittent behavior in the PlayeBaseState Move call when the player is truck by enemy. Every third or fourth hit (intermittent) - the player is popped up into the air about 1 unit (not a round number - it changes) - i dug into the code and found that just before and after the call to: stateMachine.Controller.Move in PlayerBaseState the vertical position changes suddenly and the velocity becomes a larger number (positive 200+). The character then floats back to the ground as the enemy continues attack.

I examined the CollisionFlags returned by move - and found this behavior occurred consistently when the mask came back “6” - which would appear to be an ambiguous Above and Below collision. I was able to hack a solution (below) by checking the collisions flags for an ambiguous state and resetting the y position to its value just before the Move call. I also found i needed to check for the pop up and sleep the thread for about 100 ms as well - i imagine to quiesce the internal state of the Controller. A fairly ugly hack to continue on with the training - and would welcome any guidance as to what might cause this behavior.

Cheers!

-Felgryn

    protected void Move(Vector3 motion, float deltaTime)
     {
         // need to add some logic to detect the player popping up in the air with ForceReceiver
         // save the vertical position and reset if flags come back with ambiguous collisions
         checkY = stateMachine.Controller.transform.position.y;
         CollisionFlags flags = stateMachine.Controller.Move((motion + stateMachine.ForceReceiver.Movement) * deltaTime);
 //        Debug.Log("Move 1 flags = " + flags);
         float delta = stateMachine.Controller.transform.position.y - checkY;
         if (delta > 0.5)
         {
 //            Debug.Log("Move Pop by delta " + delta);
             Thread.Sleep(100);
         }
         // there is a bug with a "6" collision - seems to be above and below - that pops the character up
         // this is a hack fix to continue until resolved - need to reach out to GameDev TV
         if ((flags != CollisionFlags.None) && (flags != CollisionFlags.Sides) &&
             (flags != CollisionFlags.Above) && (flags != CollisionFlags.Below))
         {
             // reset vertical position to where it was before the Move function
             Vector3 positionReset = new Vector3(stateMachine.Controller.transform.position.x, checkY,
                 stateMachine.Controller.transform.position.z);
             stateMachine.Controller.transform.position = positionReset;
         }
         checkY = stateMachine.Controller.transform.position.y;
 //        Debug.Log("Move 2 y = " + stateMachine.Controller.transform.position.y);
     }

I haven’t encountered this issue, so I’m not entirely sure what’s going on or why it’s happening.

I went ahead and reformatted the code for you. When pasting code in our forums, the > tag does not format for code correctly.
If you start by typing the backwards quote (next to the 1 key) three times on it’s own line, then what follows will be formatted as code. At the end of the code block, if you want to switch back, use the backwards apostrophe again three times on it’s own line.
```
{
Some code
}
```
becomes

{
    Some code
}

Hi Brian,

Many thanks for the guidance on how best to frame code in a post - greatly appreciated.

In terms of my issue - i went back through and redid the Knight implementation - needed to harmonize some of the Animations from Mixamo - so, just redid the implementation with the same back-end scripts. I think the issue might have been the window of Weapon active on the animation - perhaps causing multiple collisions with the player in the same stroke, creating the “double” collision confusion in Move. When i reduced the window size of Weapon enabled during the attack swing, this seemed to address the issue. No longer have the pop up - and am now through RagDoll - moving on to the last part of the course.

And let me reiterate - this is a >fantastic< course. Really goes into all the nitty-gritty of implementing core details of an RPG with great explanations and examples.

Cheers!

-Felgryn

1 Like

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

Privacy & Terms