Entity reaction delayed after applying torque

Hello,

project: https://playcanvas.com/project/472141/overview/20170403001jjhypercube

synopsis: I am trying to combine physics with a non physics based rotation but once I apply torque it seems like there is a delay before the ‘system’ picks back up again.

description: Its a bit hard to explain because im new to PC and 3D animation, though I am familiar with 2d animation and the concepts like lerp’ing and vectors. What I did was use some code I found in another project that multiplies some quaternions together from the camera to to a precise rotation for a cube based on the pointer device. Everything for that works fine, but at the end of a dragging interaction at mouse up I want any excess mouse movement to be applied to the rigid body as torque. When the user then clicks on the cube, I want the torque to clear out and the non physics based rotation to start back up. What happens instead is that the cube doesnt react to the dragging until a second or so after the click and drag begins again. I want the transition to be smooth from the cube spinning to it stopping with the pointer clicking and star following the pointer again.

steps to reproduce:

  1. click and hold the cube
  2. move the mouse at a slow delta while mouse pressed
  3. you should see the cube following the pointer
  4. move the pointer in a direction and release the mouse
  5. you should see it start taking torque
  6. click on the cube while its torqueing and try dragging
    result - the cube stops and pointer moves but the cube doesnt follow it until a second later
    expected - the cube should instantly stop when ‘clicked’ and begin following the pointer while dragging

Thanks

Few things to mention:

  1. If you are using physics rigidbody on an entity, then do not operate on entity using setRotation and similar methods, as it will “detach” entity from physical object.
  2. If you apply torque, have you tried just setting angularVelocity of rigidbody to 0,0,0 when mouse just got down on cube?

The example you’ve provided is fairly big with loads of code all round, which is hard to debug without clear separation of an issue. It might be very helpful if you try to replicate the functionality in separate project. This will simplify your life a lot, and you probably will figure out the solution by then.

Sorry about the disorganized code. Im trying to rapidly work through stuff. I swapped setRotation with teleport and now it works as intended. Incidentally I had tried setting the angularVelocity to 0 but for some reason it seemed to stay at 0 even when the cube should have been back in a actionable state; not sure if it was my state change handling or somehow the velocity set to 0 prevented the rotation animations.

This project is eventually going to be for rich media ad units so I may have to ask more questions along the way as I get stuck trying to understand how to work with the math inside the PC Engine.

Anyway, thanks very much for quickly responding.