随机化矢量(路径查找器)

时间:2013-12-22 07:29:09

标签: objective-c vector ios7 game-physics sprite-kit

我正在尝试随机化我的路径搜索器代码。目前,运行以下代码的sprite将移向目标。但是,我希望抛射物略微高于或低于目标。我尝试改变我的矢量点,但它似乎没有工作。有什么建议吗?

//从怪物到目标获取矢量         CGPoint vectorToTarget = vectorSubtract(self.target.position,projectile.position);

    CGPoint randomVector = CGPointMake(vectorToTarget.x + ((int)arc4random_uniform(51) - 25), vectorToTarget.y + ((int)arc4random_uniform(51) - 25));

    //Make unit vector
    CGPoint direction = vectorNormalize(randomVector);

    CGPoint shootDistance = vectorMultiplyByScalar(direction, self.screenSize.height+self.screenSize.width);
    CGPoint actualDistance = vectorAdd(shootDistance, self.position);

    float velocity = 100.0/1.0;
    float time = self.screenSize.width / velocity;

    SKAction *actionMove = [SKAction moveTo:actualDistance duration:time];

0 个答案:

没有答案