I'm started a project in SparkAR and having some trouble with getting the correct value in my script in 2 places now. Using .pinLastValue() doesn't provided the number shown in the diagnostics.
Example 1:
const directionX = Reactive.sub(Object.worldTransform.x, Target.worldTransform.x);
const directionY = Reactive.sub(Object.worldTransform.y, Target.worldTransform.y);
const directionZ = Reactive.sub(Object.worldTransform.z, Target.worldTransform.z);
Diagnostics.watch('directionX: ', directionX);
Diagnostics.watch('directionZ: ', directionZ);
Provides the values in the diagnostics:
directionX: -0.44
directionZ: -0.02
const angleRad = Math.atan2(directionX, directionZ);
Diagnostics.watch('angleRad: ', angleRad);
returns null/underfined
const angleRad = Math.atan2(directionX.pinLastValue(), directionZ.pinLastValue());
Diagnostics.watch('angleRad: ', angleRad);
returns angleRad of 0
const angleRad = Math.atan2(-0.44, -0.02);
Diagnostics.watch('angleRad: ', angleRad);
returns the correct value
Example 2:
when I call
const closestIndex = indexes.reduce((acc, cur) => Reactive.max(acc, cur));
Diagnostics.watch('Result',closestIndex);
returns closestIndex as 2
If I try to use closetIndex to find an object by name in my array it doesn't give me the 3rd object [2] in the list it just provides me the first [0]
I'm using:
Diagnostics.log(objArray[closestIndex.pinLastValue()].name);
returns object_0
where I want it to return object_2
In both these examples it doesn't return the number I want (what's in the diagnostics) but just returns 0. What am I doing wrong? Thank you for your time.