getVectorRadians( x1,  y1,  x2,  y2)
    {
        
        let len_y = y2 - y1;
        let len_x = x2 - x1;

        let tan_yx = Math.abs(len_y)/Math.abs(len_x);
        let angle = 0;
        if(len_y > 0 && len_x < 0) {
        angle = Math.atan(tan_yx)*180/Math.PI - 90;
        } else if (len_y > 0 && len_x > 0) {
        angle = 90 - Math.atan(tan_yx)*180/Math.PI;
        } else if(len_y < 0 && len_x < 0) {
        angle = -Math.atan(tan_yx)*180/Math.PI - 90;
        } else if(len_y < 0 && len_x > 0) {
        angle = Math.atan(tan_yx)*180/Math.PI + 90;
        }
        return angle;
    },


//另一种计算方式

rotationTarget(startPos,endPos){
        let direction = endPos.sub(startPos).normalize(); 
var radian = direction.signAngle(cc.v2(1,0)); //将弧度转换为欧拉角 var angle = radian / Math.PI * 180 + 90; //赋值给节点 return angle; }

  

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2021-08-15
  • 2022-02-05
  • 2021-07-15
  • 2022-12-23
  • 2021-11-23
  • 2021-09-25
猜你喜欢
  • 2022-12-23
  • 2021-11-23
  • 2021-12-03
  • 2021-06-23
  • 2021-11-23
  • 2022-12-23
相关资源
相似解决方案