Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply Angular Impulse

Here is my code for the player and the ball that interact with each other. What I want to do is to apply force to the ball like if my player is shooting it. I want the ball to move away from my player with force. how can I apply Impulse or force to this. I have tried many times but I am a newbie with Sprite Kit.

- (void) Player {
    _Player = [SKSpriteNode spriteNodeWithImageNamed:@"player1"];
    _Player.xScale = 0.09;
    _Player.yScale = 0.09;
    _Player.position = CGPointMake(self.size.width/4, self.size.height/2);
    _Player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:_Player.size];
    _Player.physicsBody.dynamic = NO;
    [self addChild:_Player];
}

- (void) TheMethodForBall {
    SKSpriteNode *sprites = [SKSpriteNode spriteNodeWithImageNamed:@"ball"];
    sprites.xScale = 0.19;
    sprites.yScale = 0.19;
    sprites.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:sprites.size];
    sprites.physicsBody.dynamic = YES;
    sprites.physicsBody.affectedByGravity = NO;
    sprites.physicsBody.allowsRotation = YES;
    sprites.physicsBody.restitution = YES;
    sprites.physicsBody.angularVelocity = 4;
    sprites.physicsBody.usesPreciseCollisionDetection = YES;
    [self addChild:sprites];
}
like image 246
Ray Avatar asked Apr 06 '14 06:04

Ray


People also ask

What is an angular impulse?

noun. : the product of a torque and its time of duration being equal to the change in angular momentum of a body free to rotate compare impulse sense 4a.

How can you apply impulse and momentum?

The impulse experienced by the object equals the change in momentum of the object. In equation form, F • t = m • Δ v. In a collision, objects experience an impulse; the impulse causes and is equal to the change in momentum.

How do you use impulse formula?

How to calculate impulse. You can type the initial and final momentum values into our calculator to find the impulse directly from the impulse formula J = Δp . You can also enter the values of mass and velocity change of an object to calculate the impulse from the equation J = mΔv .

What does angular impulse depend on?

angular momentum L is proportional to moment of inertia I and angular speed ω measured in radians per second. Unlike mass, which depends only on amount of matter, moment of inertia is also dependent on the position of the axis of rotation and the shape of the matter.


1 Answers

I think you want to apply an impulse like a kick ?

You need the following, maybe when you touch the screen / or a button

[_myBall.physicsBody applyImpulse:CGVectorMake(somePowerX, somePowerY)];

Here is another post that will help get you started

Also, this is a good tutorial for beginners.

like image 68
DogCoffee Avatar answered Nov 01 '22 16:11

DogCoffee