我正在创建一个iOS游戏,其中玩家的弓箭旋转了360度,玩家必须在正确的时间射击弓箭才能击中目标。现在,我无法让箭头朝弓的方向射击,也无法让箭头朝该方向的直角射击。 / p>
List<CourseTaken> courseTakenList =
await dbcont
.CourseTaken
.Where(c => c.CId == courseId)
.ToListAsync();
public class Student
{
public int Id;
public string Name;
public string School;
public bool Active;
}
public class CourseTaken
{
public int CId;
public string CourseName;
public int S_Id;
}
玩家将弓箭作为参考。
答案 0 :(得分:0)
您可以使用三角学将子弹的移动方向旋转self.size.height + 30
,而不是将子弹在Y方向上移动到zRotation
,在X方向上移动0像素。
let amount = self.size.height + 30
let action = SKAction.moveTo(CGPointMake(bullet.position.x + amount * sin(bullet.zRotation), bullet.position.y + amount * cos(bullet.zRotation)), duration: 0.8)
答案 1 :(得分:0)
通过从子弹的zRotation
计算力矢量,然后将其应用于子弹的physicsBody
,可以得到所需的行为。
为此,我们将使用三角学。
//adjust rotation by pi/2 radians to match spriteKits rotation system
let adjustedRotation = bullet.zRotation + .pi/2
//intensity scalar
let intensity:CGFloat = 4000 //adjust this value
//find x and y components using adjustedRotation and scale by intensity
let vx = intensity * cos(adjustedRotation)
let vy = intensity * sin(adjustedRotation)
//make vector using vx and vy components
let forceVector = CGVector(dx:vx, dy: vy)
//apply force to physicsBody
bullet.physicsBody?.applyForce(forceVector)