问题描述
所以我正在使用cannon.js在Spark AR中反弹。一切正常,直到我想通过补丁程序编辑器将Facetracker的额头位置放到脚本中。
错误:
Error:Exception in HostFunction: valueOf() called on a Signal. This probably means that you are
trying to perform an arithmetic operation on a signal like +,-,*,etc. Use functions .add,.sub(),etc on the signal instead or .subscribeWithSnapshot() on an EventSource to get the signal's current value on a callback.
at Scalarsignal::valueOf (native)
{
"line": 4841,"column": 19,"sourceURL": "cannon.js"
}
My patches,将前额的vector3发送到脚本。
var pos = Patches.getVectorValue('HeadPos');
groundBody.position.set(pos);
可悲的是,我在网上找不到任何有关将矢量3从补丁发送到脚本中的“工作”值的信息,有人知道如何将矢量3值发送给脚本并将其用作值吗? >
解决方法
我在使用cannon.js时发现了一种困惑。 cannon.js具有一种更新功能,因此您可以使用.pinLastValue(),因为它每帧都要执行一次以更新物理。
我的代码:
// Create time interval loop for cannon
Time.setInterval(function (time) {
if (lastTime !== undefined) {
let dt = (time - lastTime) / 1000;
world.step(fixedTimeStep,dt,maxSubSteps)
// Get the head position values from the patches
var headVal1 = Patches.getScalarValue("HeadPosX").pinLastValue();
var headVal2 = Patches.getScalarValue("HeadPosY").pinLastValue();
var headVal3 = Patches.getScalarValue("HeadPosZ").pinLastValue();
// Set the position of the head hitbox to the headposition in the physics world
HeadBody.position.x = headVal1;
HeadBody.position.y = headVal2;
HeadBody.position.z = headVal3;
}
lastTime = time
},timeInterval);
这段代码分别从补丁中分别获取x,y和z值,在这些补丁中我也分别发送这些值。我也可以从两侧将其作为Vector3来完成,但是我认为这样做看起来更好,并且可以更轻松地通过补丁分别编辑值,而不是再次将其打包为Vector3。