我有一个非常令人沮丧的时间来完成这个,所以任何有关此事的帮助将不胜感激.谢谢.
解决方法 基本步骤是>计算从抛射物发射器到鸟类的矢量分量
>标准化组件(可选)
>通过缩放(标准化)组件来创建矢量
>使用矢量向射d施加冲动
这是一个如何做到这一点的例子
OBJ-C
// Calculate vector components x and yCGfloat dx = bird.position.x - launcher.position.x;CGfloat dy = bird.position.y - launcher.position.y;// normalize the componentsCGfloat magnitude = sqrt(dx*dx+dy*dy);dx /= magnitude;dy /= magnitude;// Create a vector in the direction of the birdCGVector vector = CGVectorMake(strength*dx,strength*dy);// Apply impulse[projectile.physicsBody applyImpulse:vector];
迅速
// Calculate vector components x and yvar dx = bird.position.x - launcher.position.xvar dy = bird.position.y - launcher.position.y// normalize the componentslet magnitude = sqrt(dx*dx+dy*dy)dx /= magnitudedy /= magnitude// Create a vector in the direction of the birdlet vector = CGVector(dx:strength*dx,dy:strength*dy)// Apply impulseprojectile.physicsBody?.applyImpulse(vector)总结
以上是内存溢出为你收集整理的ios – Sprite Kit – 使用Impulse在角色上射击射d全部内容,希望文章能够帮你解决ios – Sprite Kit – 使用Impulse在角色上射击射d所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)