Spin box/camera around with velocity in SceneKit

140 Views Asked by At

Aspects of .allowcameracontrol are perfect for my use. I'm currently rotating a camera node (child of a sphere) around a cube. I'd like to have the spinning gradually come to a halt (like allowscameracontrol).

Can anyone assist in direction of how to slowly stop spinning based on velocity of the gesture? Add friction to the camera?

1

There are 1 best solutions below

0
On BEST ANSWER

I spent a lot of time working on this, and it's actually a tricky subject. The best approach I found is to:

  1. Save the past 10 or so drag events every frame
  2. On release, calculate a velocity for X and Y axis based on these frames
  3. Keep moving the camera using these velocity values
  4. Every frame, dampen the velocity. Looking at spring equations will help you make it more realistic
  5. When the velocity is under a small threshold, stop moving to avoid endless drifting