Continuous 3d Rotation Value
Hi, How do we get forward a linear rotation continually similar to transformation of this 3D program.
I tried it with this code in lens studio
// @input Component.Camera trackCam
// @input Component.Text myText
var letReset = true;
var x;
var updateEvent = script.createEvent("UpdateEvent")
updateEvent.bind(function(){
x = script.trackCam.getTransform().forward.x
script.myText.text = x.toFixed(2)
})
but I get this result
never exceeds 1 then it goes back to 0 again.
I just want to track the continuous rotation of the camera.
Thank you for your help and support
I don't work with transforms a lot, but according to the docs "forward" returns a directional vector, so the 0-1 may be because it is a unit vector.
Is there any reason you aren't using getWorldRotation()? I don't think it will give you that continuous rotation, but you could setup some variables and track that yourself.
Before we tried using transform rotation but it is in quat so it also returns a value of 1 to 0's aswell. And seems like we having a lot of bugs using quat because it often goes from positive value then instantly goes to negative value at some point when we turn around.
If continues rotation value is not possible within lens studio. Is there a way to know if the camera is rotating towards left or right? I know it can be achieve using transform rotation but it gives me a bug because the value returns positive then instantly turns into negative
LS has built-in methods for converting from quaternion to euler angles. You will still get jumps because LS doesn't measure angles 0-360 but rather -180 to 180 or something like that.
For the rotation direction it is just whether the difference between two consecutive readings is positive or negative.
To handle the positive/negative and value jumps you can remap the angles or write some logic to handle them.
how do I do that you said "remap the angles" ?
That's up to you to figure out. If you don't like the jump you'll need to write a function that takes in the angle and returns a different value. So if the angles that Snapchat give you are -180 to 180, you could write a function that transforms those values to a 0-360 scale. If I remember correctly it isn't as simple as adding 180 to the angle; I think there is a weird jump somewhere in there so you'll need to handle that with your conversion function.
I actually tried everything you said but that jump from positive to negative value is still exist, that is the reason of the bugs on our projects. I hope someone can give solution to this problem