Lerp not working, probably quaternion?
-
Hello guys, I'm trying to make a smooth following vehicle camera and this is the code so far:
Camera cam = World.RenderingCamera; Entity target = playerVeh; float damping = 1f; // used for smoothing the following camera, my DeltaTime is bugged, I don't know how to fix the jumping camera... bool smoothRotation = true; float rotationDamping = 1.0f; cam.AttachTo(target, new Vector3(0f, -6f, 1.5f)); //cam.Position = Vector3.Lerp(cam.Position, wantedPosition, DeltaTime.getDeltaTime() * damping); if (smoothRotation) { Quaternion wantedRotation = LookRotation(target.ForwardVector, target.UpVector); cam.Rotation = Quaternion.Slerp(Quaternion.Euler(cam.Rotation), wantedRotation, DeltaTime.getDeltaTime() * rotationDamping).Axis; } else { cam.PointAt(target, new Vector3(0f, 5f, 0f)); cam.Rotation = new Vector3(cam.Rotation.X + (1 / playerVeh.SteeringAngle), cam.Rotation.Y, cam.Rotation.Z); cam.MotionBlurStrength = playerVeh.Speed / 10; }
The LookRotation method is the same as the one that unity3d uses, why is the camera not rotating? Also for the deltaTime, what is the best method to use in C#?
This is the DeltaTime class:public static float deltaTime = 10f; public static float lastTime = Environment.TickCount; public DeltaTime() { this.Tick += onTick; } void onTick(object sender, EventArgs e) { var currentTick = Environment.TickCount; if (currentTick - lastTime >= 1000f) { lastTime = currentTick; } deltaTime = currentTick - lastTime; } public static float getDeltaTime() { return deltaTime / 1000f; }
I need help please! Thank you!