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
5
votes
1 answer

SpriteKit Weird 'PKPhysicsBody' Crash

I am trying to implement a simple category for SKPhysicsBody that will allow me to apply 'perfect bouncing' to a physics body. What this will simply do is when perfectBouncing = YES the following will happen: restitution = 1.0 linearDamping =…
Hamish
  • 78,605
  • 19
  • 187
  • 280
5
votes
1 answer

Sprite Kit - Apply Impulse to shoot projectile at character

I am developing a game using Sprite-Kit (Objective-C). It's a game where you control a bird in flight and arrows and other bad projectiles are shot at you from the right/top/bottom sides of the screen. I am using physics instead of an SKAction in…
Mike Simz
  • 3,976
  • 4
  • 26
  • 43
5
votes
1 answer

physicsBody is misaligned with spriteNode

I am creating a spritenode, setting its position and changing its anchorpoint to (0, .5) and then creating a phyicsbody. The physicsbody thinks my anchorpoint is still at (.5, .5), stupidly. The same problem is referenced here, but unsolved:…
Max Hudson
  • 9,961
  • 14
  • 57
  • 107
5
votes
1 answer

Sprite Kit bodyAtPoint and bodyInRect return incorrect values?

I created a very simple sample code, just one scene, one sprite node 20x20px, at point 0.0 on screen. When I call scene.physicsWorld bodyAtPoint it returns me this node even at point eg: 34x34. But at point 35x35 it returns null. So basically all…
DamianD
  • 101
  • 1
  • 4
5
votes
1 answer

SKAction scale physicsBody

I don't really know where to start. I have an image of a circle stored in an SKSpriteNode and a physicsBody that mirrors the size when it is created. I am using an SKAction to scale down the size of the image though, and the physicsBody remains the…
Max Hudson
  • 9,961
  • 14
  • 57
  • 107
5
votes
4 answers

How can I prevent the child of an SKSpriteNode from rotating with its parent?

I'm using SpriteKit to write an iOS game that involves a number of labeled balls. I'm constructing these 'rollingBalls' by building a parent SKSpriteNode with 2 children: a) an SKShapeNode (the actual circle shape) b) and an SKLabelNode (the…
doublea
  • 2,546
  • 1
  • 23
  • 35
4
votes
2 answers

Set a minimum rolling speed

I have a ball, which I fire into the air: And it is initialised like so: func initBallNode() { // TODO: Create ball node ballNode = SKSpriteNode(imageNamed: "Ball1") // Create a ball ballNode.zPosition = ZPositions.ball let…
George
  • 25,988
  • 10
  • 79
  • 133
4
votes
2 answers

Spritkit : Detect collision while drawing line using finger

I am trying to detect collision contactPoint between existing line and line which user currently drawing using finger. Here is my code : let padding: CGFloat = 100 override func didMove(to view: SKView) { physicsWorld.contactDelegate = self …
Devang
  • 11,258
  • 13
  • 62
  • 100
4
votes
1 answer

Physics velocity causes parent to separate from child

I'm trying to make infinite scrolling terrain by programmatically adding/deleting textured tiles as the player pans the view. New tiles should only be added next to existing tiles that have an open edge. To detect if a tile has an open edge, I plan…
4
votes
1 answer

Swift 3 (SpriteKit): Aligning SKPhysicsBody to SKShapeNode

I am creating SKShapeNodes in my program using this: let points = [CGPoint(x: x, y: y), CGPoint(x: x2, y: y2)] let line = SKShapeNode(points: &points, count: points.count) The problem that I am having is that whenever I add a physicsBody to the…
J.Treutlein
  • 963
  • 8
  • 23
4
votes
2 answers

SpriteKit physics huge FPS drop on iOS 9

I'm experiencing a huge FPS drop in the scene with a few static SKSpriteNode nodes that have bodies defined with SKPhysicsBody init(polygonFrom: CGPath) and some simple, dynamic SKSpriteNode nodes with bodies defined with init(rectangleOf:…
damirstuhec
  • 6,069
  • 1
  • 22
  • 39
4
votes
2 answers

Designing physics bodies other than circles

I'm making my first game with SpriteKit and for the enemy aliens (SKSpriteNode subclass) physics bodies I have been using: self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width/2) this has worked so far as most of the aliens are…
muZero
  • 948
  • 9
  • 22
4
votes
1 answer

How do I calculate a vector that is away from the camera?

I have a simple sphere and a UITapGestureRecognizer. When tapped, I would like to apply a force that moves the sphere away from the camera. func sceneTapped(recognizer: UITapGestureRecognizer) { let sceneView = self.view as! SCNView let…
i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
4
votes
1 answer

Physics Body for SKLabelNode in SpriteKit?

How do I create a Physics Body for a string of characters in SpriteKit? I don't want it to be a rectangle around the font, I want each letter to be its own shape for contact.
Logan Jahnke
  • 815
  • 8
  • 21
4
votes
1 answer

Angular Impulses

So I'm using angular impulses to rotate a sprite with a physicsBody. I want one side of the screen to apply an impulse in one direction, whilst the other side of the screen will apply an impulse in the other direction (see code below). override…