SpriteKit物理学:平等和相反的反应

时间:2014-10-03 18:27:31

标签: ios sprite-kit skphysicsbody

我正在尝试使用虚拟操纵杆为我的游戏中的直升机制作动画。如果您主动飞行,下面的代码效果很好,但是现在我想让直升机动画,将其旋转到负角度并向其施加负/正向量,使其快速停止并“悬停”。并且可能来回反弹直到它徘徊。有什么建议吗?

//Just move the hell with no physics
//[heli setPosition:CGPointMake(heli.position.x+self.joystick.x*2, heli.position.y+self.joystick.y*2)];

//Apply physics to the heli
float multiplier = 2.5;
[heli.physicsBody applyForce:CGVectorMake(_joystick.x*multiplier, _joystick.y*multiplier)];

//joystick x position is -99 to 99 
SKAction *rotation = [SKAction rotateToAngle:-1*(_joystick.x/2.0) duration:0];

[heli runAction: rotation];

//if i let go of the joystick it returns to zero - bounce to a hover
if (_joystick.x == 0) { //not working
    //check the current velocity?
    //[heli.physicsBody velocity];
    [heli.physicsBody applyForce:CGVectorMake(-1*(_joystick.x*multiplier*2), -1*(_joystick.y*multiplier*2))];
}

0 个答案:

没有答案