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
47
votes
3 answers

Performing your own physics calculations for a collision in Sprite Kit

I'm trying to set up some elastic collisions using Sprite Kit. There is an issue with the case of multiple objects resting near each other as I asked in Sprite Kit Physics Collision Issue I am confused on the timing of the situation for a…
Cherr Skees
  • 1,508
  • 2
  • 21
  • 37
36
votes
7 answers

Physicsbody doesn't adhere to node's anchor point

My scene has a bunch of rectangles with physics bodies that are the same size as the rectangle. I like to anchor all of my objects to CGPointZero, however I've noticed when I do that the physicsbody remains anchored in the middle. In other words,…
Sophie McCarrell
  • 2,831
  • 8
  • 31
  • 64
31
votes
8 answers

Is there a way to visually see sprite kit's SKPhysicsbody borderline?

I am using bodyWithPolygonFromPath to define the volume of a physics body, and I used http://dazchong.com/spritekit/ to get the paths required. But the path does not seem correct and I wish to see the borderline of the physics body path to see if…
user2832367
  • 381
  • 1
  • 3
  • 8
28
votes
2 answers

How does collisionBitMask work? Swift/SpriteKit

As far as I'm aware the default for Physics bodies is to bounce off each other when they hit each other until you set their collisionBitMask to an equal number. However, I'm having a huge issue accomplishing what seems like it should be very simple…
Barkley
  • 6,063
  • 3
  • 18
  • 25
16
votes
2 answers

applyForce(0, 400) - SpriteKit inconsistency

So I have an object that has a physicsBody and gravity affects it. It is also dynamic. Currently, when the users touches the screen, I run the code: applyForce(0, 400) The object moves up about 200 and then falls back down due to gravity. This only…
Max Hudson
  • 9,961
  • 14
  • 57
  • 107
14
votes
2 answers

Can't understand how collision bit mask works

I am trying to use collision bit masks and contact test bit masks in Swift, I want two objects not to collide together, so I am doing : firstNode.physicsBody?.collisionBitMask = 0b01 secondNode?.collisionBitMask = 0b10 Since SpriteKit does an AND…
Pop Flamingo
  • 3,023
  • 2
  • 26
  • 64
11
votes
2 answers

A way to apply zRotation so that it affects the SKPhysicsBody accordingly?

Let's say I have a SKSpriteNode that represents a car wheel, with a circular SKPhysicsBody successfully attached to it. The genre would be sideways scrolling 2d car driving game/simulator, obviously. What I want is to calculate all the in-motor…
11
votes
1 answer

SpriteKit: How to create Basic Physics Joints

I am trying to create simple Joints between two SKPhysicsBodies. But, they are acting weirdly. I am well aware of the fact the anchor points should be on scene coordinate. Please have a look at the Source code attached. For Example this is how a…
Bavan
  • 1,021
  • 1
  • 10
  • 24
10
votes
1 answer

SpriteKit iPhone/iPad different resolution, need same physics

As I am porting an iPhone app that uses SpriteKit to iPad, I have been able to scale all the screen elements and font sizes using the height ratio of the iPhone 5 to iPad screen. Everything looks proportional, except for the physics since there is…
Edward
  • 518
  • 3
  • 13
9
votes
4 answers

Animation atlas and dynamic physicsBody in Swift 3

I did a small test project using the "Hello World" Sprite-kit template where there is an atlas animation composed by these frames: - I want to show this knight and it's animation. I want to set a DYNAMIC physics body. So I've used a tool to…
Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
9
votes
3 answers

Flipped x-scale breaks collision handling (SpriteKit 7.1)

I use SKNode's xScale property to flip my sprites horizontally. Now, after updating iOS to version 7.1 horizontal flip causes my objects to sink inside the ground. (See animation below). The problem occurs only with xScale property. Vertical flips…
JKallio
  • 903
  • 5
  • 15
9
votes
5 answers

SKPhysicsBody bodyWithPolygonFromPath memory leaks

I have a strange memory leaks when creating Sprite Kit physics bodies with custom shapes. This is how my implementation looks: CGFloat offsetX = self.frame.size.width * self.anchorPoint.x; CGFloat offsetY = self.frame.size.height *…
Darrarski
  • 3,882
  • 6
  • 37
  • 59
8
votes
2 answers

how to set physics properties for a circle so it follows given path

The movement of a physics body circle is too erratic for what I want to achieve. I would like to restrict it so it follows a certain path touching specific points (or a range of points) as shown in the image below. How can I set the physics…
NSSwift
  • 395
  • 1
  • 12
8
votes
1 answer

How to copy SKSpriteNode with SKPhysicsBody?

I am curious about a situation that I came across today when trying to unarchive and copy a SKSpriteNode from one SKScene to another. In the output from the playground below you can see that both linearDamping and angularDamping or not being…
fuzzygoat
  • 26,573
  • 48
  • 165
  • 294
8
votes
6 answers

didBeginContact is being called multiple times for the same SKPhysicsBody

func didBeginContact(contact: SKPhysicsContact) { if ( contact.bodyA.categoryBitMask & BodyType.shield.rawValue ) == BodyType.shield.rawValue { contact.bodyB.node?.removeFromParent() counter++ println(counter) }…
Bryan N
  • 111
  • 4
1
2 3
54 55