Ios 精灵套件中玩家移动的最佳路径

Ios 精灵套件中玩家移动的最佳路径,ios,swift,sprite-kit,Ios,Swift,Sprite Kit,我在这里要做的是,让角色移动到一个位置,同时避免在他的道路上遇到障碍。我试着用这样的方法: // node = character // position = position of touch [self.map enumerateChildNodesWithName:@"tile" usingBlock:^(SKNode * _Nonnull tileNode, BOOL * _Nonnull stop) { if( round((SDistanceBetween

我在这里要做的是,让角色移动到一个位置,同时避免在他的道路上遇到障碍。我试着用这样的方法:

// node = character 
// position = position of touch

[self.map enumerateChildNodesWithName:@"tile" usingBlock:^(SKNode * _Nonnull tileNode, BOOL * _Nonnull stop) {        
    if( round((SDistanceBetweenPoints(node.position, tileNode.position)) < 33) ) {
        if((SDistanceBetweenPoints(tileNode.position, position) < newDistance)&&((tileNode.position.x == position.x) || (tileNode.position.y == position.y))) {
            newDistance = SDistanceBetweenPoints(tileNode.position, position);
            moveToTouch = tileNode.position;
        }
    }
}];
//节点=字符
//位置=触摸的位置
[self.map enumerateChildNodesWithName:@“tile”usingBlock:^(SKNode*\u Nonnull tileNode,BOOL*\u Nonnull stop){
if(圆形((点之间的SDistance(node.position,tileNode.position))<33)){
if((点(tileNode.position,position)
我的主要问题是,角色在半路上开始向右行走:


SKSpriteNodes的坐标是基于精灵的中心,而不是像UIView那样的左上角。考虑到这一点,尝试相同的代码

SKSpriteNodes的坐标是基于精灵的中心,而不是像UIVIEW那样的左上角。考虑到这一点,你能尝试同样的代码吗。。。这确实解决了我的问题!谢谢(作为答案张贴)。