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);
}