参考Cocos Creator 3D Node的forward问题 - 知乎 (zhihu.com)
代码
public static setNodeForward(node: Node, dir: Vec3) {
var q: Quat = new Quat();
Quat.rotationTo(q, node.forward, dir);
node.rotation = q;
}
这个没有做前后的归一和一致判断会闪烁
let newForward=dir.normalize();
let oldForward=node.forward;
oldForward.x-=newForward.x;
oldForward.y-=newForward.y;
oldForward.z-=newForward.z;
if(oldForward.x<-0.0001||oldForward.x>0.0001
||oldForward.y<-0.0001||oldForward.y>0.0001
||oldForward.z<-0.0001||oldForward.z>0.0001 )
{
let q: Quat = new Quat();
Quat.rotationTo(q, this.node.forward, newForward);
this.node.setRotation(q);//
}