public virtual void PhysicsUpdate() // FSM so this is fixedupdate monobehaviour
{
Move();
}
protected virtual void Move()
{
if (sm.character.IsOnSlope() == true)
{
sm.character.rb.AddForce(GetSlopeMoveDirection() * moveSpeed * 10f, ForceMode.Force);
}
else
{
sm.character.rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
}
protected void SpeedControl()
{
if (sm.character.IsOnSlope() == true)
{
if (sm.character.rb.velocity.magnitude > moveSpeed)
{
sm.character.rb.velocity = sm.character.rb.velocity.normalized * moveSpeed;
}
}
else
{
Vector3 flatVel = new Vector3(sm.character.rb.velocity.x, 0f, sm.character.rb.velocity.z);
if (flatVel.magnitude > moveSpeed)
{
Vector3 limitedVel = flatVel.normalized * moveSpeed;
sm.character.rb.velocity = new Vector3(limitedVel.x, sm.character.rb.velocity.y, limitedVel.z);
}
}
}
IEnumerator PostSimulationUpdate()
{
YieldInstruction waitForFixedUpdate = new WaitForFixedUpdate();
while (true)
{
yield return waitForFixedUpdate;
SpeedControl();
Rotate();
}
}
this is my movement code. but I have no idea what is difference between speedControl placed in fixedupate and update or waitforfixedupdate. when SpeedControl() placed in fixedupdate, lets assume max speed is 5. then the actual speed is like 5.9 in unity inspector but if I placed SpeedControl() update or waitforfixedupdate, the speed become 5 in unity inspector. I dont know why. the actual physics calculation calculate in internal physics engine right? so it doesnt matter if the SpeedControl() is placed in update or fixedupate isnt it? the actual speed is same with fixedupate or update but only different in unity inspector?