scyth3s's picture

Update Loop Fluctuation causing issues

I'm making a basic 3D game-ish demo (nothing special), and having an issue where all of a sudden, my camera teleports randomely away from my scene. I have done minimal testing, but I believe it corrosponds with the instances when the GameWindow's update rate shoots up from the target 30 to something like 40,000, thus screwing up the time-based movement algorithm with a number that may not be divided correctly. Does anyone have any insight?

public void Update(double time)
        {
            foreach (IBehavior behavior in Behaviors)
            {
                behavior.Update(this);
            }
 
            NormalizeVelocity();
            NormalizeRotationDelta();
 
            _velocity.X = Speed * _velocity.X / (float)time;
            _velocity.Y = Speed * _velocity.Y / (float)time;
            _velocity.Z = Speed * _velocity.Z / (float)time;
 
            Matrix4 rotation = Matrix4.CreateRotationX(RotationDelta.X);
            Matrix4 translation = Matrix4.CreateTranslation(_velocity);// * (MAX_SPEED / (float)time));
 
            Matrix4 transformation;
            Matrix4.Mult(ref rotation, ref translation, out transformation);
 
 
            Matrix4.Mult(ref _world, ref transformation, out _world);
            World *= Matrix4.CreateRotationY(RotationDelta.Y);
 
            _velocity = Vector3.Zero;
            RotationDelta = Vector3.Zero;
        }

This causes an issue

Inline Images