计算的距离上感觉有问题,求大神解惑

新人学习教程,每次怪兽和星星的距离明显没到达设定值,但是打印出来的距离确在设定值之内,星星也消失了,这是怎么回事,求教呀~~~
以下是代码

cc.Class({
extends: cc.Component,

properties: {
    //预制件星星
    psesd: {
        default: null,
        type: cc.Prefab
    },
    //小怪兽
   skss:{
    default: null,
    type: cc.Node
   },
   //背景
   ground:{
    default: null,
    type: cc.Node
   }

},

// LIFE-CYCLE CALLBACKS:
onLoad () {
   this.Players = this.skss;//主角小怪兽
   this.groundY = this.ground.y + this.ground.height/2;//获取地平面位置
   this.shengcheng();
},
// 生成预制物体星星
shengcheng(){
    this.tPrefab = cc.instantiate(this.psesd);
    this.tPrefab.parent = this.node;
    this.tPrefab.setScale(0.5, 0.5)
    this.tPrefab.setPosition(this.getNewStarPosition());
},
//随机生成星星的坐标
getNewStarPosition: function () {
    var randX = 0;
    // 根据地平面位置和主角跳跃高度,随机得到一个星星的 y 坐标
    var randY = this.groundY + Math.random() * this.Players.y + 50;
    // 根据屏幕宽度,随机得到一个星星 x 坐标
    console.log(this.node.width)
    var maxX = this.node.width/2;
    randX = (Math.random() - 0.5) * 2 * maxX;
    // 返回星星坐标
    return cc.v2(randX, randY);
},
start () {
},

update (dt) {
    //计算星星与小怪兽之间的距离
    var playerPos =this.tPrefab.getPosition()
var dist = this.Players.position.sub(playerPos).mag();

if(dist<50){
    //消除星星
        this.tPrefab.destroy();
        //重新生成随机星星
        this.shengcheng()
   }
},

});

会不会是父节点不一致导致坐标系不一样?

应该是节点座标不一致,可以把座标转换到相同父节点,或者转成世界座标

确实是这个问题,感谢感谢啦:blush:

是的,十分感谢:blush:我将小怪兽的节点node赋值父节点距离就好了,但是跳动会有重影,会不会是因为每次都要计算相对于父节点的位置后再渲染,造成的迟缓呢?

啊啊,就当我没说第二个问题吧。。。是因为跳药时间设定太短

没事儿,大家都是这样过来的