求旋转角度的问题

先感谢之前帮忙做调的几位大神 ~

现在旋转很奇怪~还是来求助了!

在飞机飞行时,我记录上一帧的坐标,再通过当前帧的坐标求向量夹角,但不知道为什么就是不对~而且与C++的不同,求夹角时需要传入另一个vec2

Rotation_function:function(){
        
        this.currentP = this.node.position;
        var rotationAngle = this.currentP.angle(this.lastP) / Math.PI * 360;
 
        this.node.rotation = rotationAngle;
        // console.log(rotationAngle);
        
        this.lastP = this.currentP;
        // console.log(this.currentP);
    },

求大神 帮忙

随带一提~图是向右的~

不应该求两个向量的夹角吧,如果要求运动方向,是用两个坐标的差来表示速度,再求这个速度的方向角。(也就是算currentP - lastP的角度)

creator计算指定向量的弧度应该是用cc.pToAngle

另外你上面的算式,pi是180,你最后乘以360是2pi了…

    this.currentP = this.node.position;
    var p = this.currentP.sub(this.lastP);
    var rotationAngle = cc.pToAngle(p);
    this.node.rotation = rotationAngle;
    this.lastP = this.currentP;

这样处理还是不对。。。。。再次求教~

pToAngle是弧度,要换成角度吧,除以pi乘以180

这个方法也试过了~也是不对~我也无语了~

    var currentP = cc.p(this.node.x, this.node.y)
    var deltaP = currentP.sub(this.lastP)
    var angle = cc.pToAngle(deltaP) / Math.PI * 180
    this.node.rotation = -angle
    this.lastP = currentP

刚刚去试了一下,这个rotation是顺时针转的,算出来的angle是逆时针转的,rotation = -angle就好了。

1赞