Questions tagged [skphysicsbody]

An SKPhysicsBody object is used to add physics simulation to a node. When a scene processes a new frame, it performs physics calculations on physics bodies attached to nodes in the scene. These calculations include gravity, friction, and collisions with other bodies. You can also apply your own forces and impulses to a body. After the scene completes these calculations, it updates the positions and orientations of the node objects.

An SKPhysicsBody object is used to add physics simulation to a node. When a scene processes a new frame, it performs physics calculations on physics bodies attached to nodes in the scene. These calculations include gravity, friction, and collisions with other bodies. You can also apply your own forces and impulses to a body. After the scene completes these calculations, it updates the positions and orientations of the node objects.

To add physics to a node, create and configure an SKPhysicsBody object and then assign it to the physicsBody property of the SKNode object. A physics body must be associated with a node object before you apply forces or impulses to it.

Click Here for Apple's Documentation of SKPhysicsBody.

812 questions
0
votes
1 answer

- (void)didBeginContact:(SKPhysicsContact *) refuses to fire

1) I set the delegate protocol on the SKScene header: @interface WorldScene : SKScene 2) I set delegate to the physics world: - (id) init { self = [super init]; if (self) { self.physicsWorld.gravity =…
0
votes
0 answers

How to add Bodies to a SKPhysicsWorld

I'm developing a running game for iOS devices and have run into a problem. I created a subclass for a game tile which is 4 screen lengths long. The game tile will have some nodes which are obstacles. I have a scene which creates the player, some…
67cherries
  • 6,931
  • 7
  • 35
  • 51
0
votes
2 answers

Using a UIPanGestureRecognizer to flick a SpriteKit sprite

I'm trying to use UIGestureRecognizers to be able to move a sprite around within a SpriteKit scene. So far it moves around just fine, but it stops as soon as I take my finger off the screen. What I want to do now is translate the gesture end into a…
0
votes
1 answer

Keeping an SKShapeNode within the bounds of an SKSpriteNode

I must be missing something really obvious here. My objective: Create a box in the center of the screen, with a bouncing ball staying inside that box. I'm trying to create an edge-based SKSpriteNode for the bounding box and an volume-based…
Thunk
  • 4,099
  • 7
  • 28
  • 47
0
votes
1 answer

SKSpriteNode not affected by gravity for custom physicsBody

I am creating a custom edge path for a SKSpriteNode's physicsBody. CGMutablePathRef edgePath = CGPathCreateMutable(); CGPathMoveToPoint(edgePath, NULL, -100, -70); CGPathAddLineToPoint(edgePath, NULL, -100, 40); CGPathAddLineToPoint(edgePath, NULL,…
ZeMoon
  • 20,054
  • 5
  • 57
  • 98
0
votes
1 answer

Sprite kit iOS 7 bodyWithPolygonFromPath error

I am attempting to create a physics body around a sprite, but when using bodyWithPolygonFromPath, I got the error message "SKPhysicsBody: Error attempting to create polygon with 18 vertices, maximum is 12". I then tried to use a different option…
mhillsman
  • 770
  • 1
  • 8
  • 26
0
votes
1 answer

SpriteKit physicsBody always upright

I have a spritenode with a physics body that is affected by gravity and dynamic, however, when it hits things it rotates. I am only using the physicsbody for the Y axis gravity, and nothing else. When it hits something horizontally, I don't want it…
Max Hudson
  • 9,961
  • 14
  • 57
  • 107
0
votes
1 answer

SKPhysicsBody change animation/physics speed

Is there any way to change the animation/physics speed of physicsbody? I want the update method to be called 60 times a second still, I just want everything on the screen to move slowly, but still have the same property values (ie a velocity (10,…
Max Hudson
  • 9,961
  • 14
  • 57
  • 107
0
votes
1 answer

Sprite Kit How to change physics body programatically

How can I change a sprite's physics body programatically? Here's what I'm doing: [mySprite removeFromParent]; mySprite.physicsBody = [MySprite body2]; // body setup [myContainer addChild: mySprite]; But somehow it just doesn't work. What am I doing…
Skiny
  • 405
  • 1
  • 4
  • 16
0
votes
1 answer

How to change the gravity in a SKAction?

I am making a game in Sprite Kit and I am wondering if it is possible to make a SKAction which changes he gravity for a while, is it? This is the code I already have: SKSpriteNode *sprite = [SKSpriteNode…
Vince
  • 648
  • 1
  • 7
  • 17
-1
votes
1 answer

How to archive and unarchive an SKPhysicsBody array using UserDefaults since iOS 12.0

I can successfully archive and unarchive an array of SKPhysicsBody's using UserDefaults as below but the unarchive process has been deprecated. This is the warning message... 'unarchiveObject(with:)' was deprecated in iOS 12.0: Use…
-1
votes
1 answer

Having problems with a Parent and Child nodes when they each have an SKPhysicsBody

I have an SKSpriteNode that I set above the screen, so that it'll drop from above. So it does have an SKPhysicsBody that affectedByGravity. But that's only so it drops down from above, there will be no collision detection. The node itself has 6…
Caractacus
  • 83
  • 7
-1
votes
2 answers

Cannot assign PhysicsBody and property to an SKSpriteNode?

I'm building a function in which a random variable will choose 1 in 4 SKSpritenode in an array and assign itself to it. However, that randomline, although appear as expected on the screen, does not contain any physicsbody property so it cannot be…
Khoi Le
  • 3
  • 4
-1
votes
2 answers

Gravity value in SpriteKit game scene

I'm trying to create a game using Apple's SpriteKit game engine. While implementing some physics-based calculations in the game, I noticed that the calculated results differ from what effectively then happens to objects. Example: calculating a…
Emilio Schepis
  • 1,677
  • 2
  • 9
  • 11
-1
votes
1 answer

SKPhysics turn off isDynamic after it reaches a certain position

How can I go about approaching this? I want to turn off isDyanmic after my sprite has approached a certain position. So basically how do I do something after something has occurred in swift? Thanks in advance
phindle
  • 73
  • 5