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

SpriteKit SKPhysicsBody bodyWithTexture is Upside Down

Hi I'm trying to fix this bug with spritekit's physics shape appearing upside down. [SKPhysicsBody bodyWithTexture:monsterTexture size:monsterTexture.size] The first time the monster appears the phsyics body orientation is correct. But the second…
8
votes
4 answers

iOS Swift didBeginContact not being called

I have been struggling for the past two days to get two SKSpriteNodes to register a collision and evoke didBegin#contact. I've set their bit masks 'categoryBitMask', 'contactTestBitMask' and 'collisionTestBitMask' for both objects. I've also set the…
8
votes
2 answers

SpriteKit detect collision without setting dynamic to true?

I want my sprites collisions and contacts to be detected, but I don't want them to move dynamically (I just need to know that they've touched). didBeginContact(contact: SKPhysicsContact!) is only called if I set my player's physicsBody.dynamic to…
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
7
votes
1 answer

How to implement a physical effect in SimCity 5, that a building swings when it is being moved?

It is hard to describe in plain text, so I recorded a GIF to demonstrate. https://public.lightpic.info/image/2B1F_582465841.gif I am currently working on a project that requires such effect. Up to now I have finished a similar effect on iOS with…
Source
  • 81
  • 7
7
votes
4 answers

Giving physics to tiles of SKTileMapNode in Xcode 8

I am learning Swift, and as a project I am working on a tile based 2D game similar to super mario where my character will walk and jump on tiles. The latest version of Xcode and Sprite Kit give the ability to create a Tile Map directly in Xcode. In…
MJ1986
  • 91
  • 1
  • 2
7
votes
1 answer

Swift: Set velocity for distance

I'm trying to make a moving platform on Swift and, in order to make the player move together with the platform, I needed to change the self.moveByX(), which was much simpler, to the physicsBody?.velocity (and add some friction to both platform and…
Sergio Toledo Piza
  • 793
  • 1
  • 6
  • 27
7
votes
1 answer

Change SpriteNode PhysicsBody Size at Run Time

I want to be able to change a node's physicsBody height when the user swipes downwards, but have not been able to find out how to do this, beside resetting the entire physicsBody. When I originally load the node, I use the below code: …
Jarron
  • 1,049
  • 2
  • 13
  • 29
7
votes
4 answers

Binary operator '~=' cannot be applied to operands of type 'String' and 'String?'

I have a simple switch-statement that is not that simple. switch(bubble?.name){ //bubble is SKPhysicsBody case "largeBubble": // <= error newBubbleSize = "medium" break; default: newBubbleSize = "large" …
Jurik
  • 3,244
  • 1
  • 31
  • 52
7
votes
1 answer

SKSpriteNode subclass: method to remove all joints

I have created a subclass of SKSpriteNode. I connect instances of that class together with joints of type SKPhysicsJointLimit. I do this within my didEndContact(contact: SKPhysicsContact) in my GameScene: var joint =…
silmor-vie
  • 101
  • 5
7
votes
2 answers

Incorrect behaviour with SKPhysicsJointPin when shouldEnableLimits is true and lowerAngleLimit and upperAngleLimit set

I currently have a ragdoll figure, which consists of a parent node (with no physics bodies attached), and lots of child nodes which each consist of a circle body. The circles are connected to each other using an SKPhysicsJointPin between each…
Robert
  • 5,735
  • 3
  • 40
  • 53
7
votes
2 answers

SKFieldNode magneticNode attracting forces

I am currently working with the iOS 8 SpriteKit API's and am having a hard time creating an attractive magnetic force with SKFieldNode. I can create an opposing magnetic force just fine, however I can't reverse the field. Heres what I have…
satvikb
  • 319
  • 1
  • 3
  • 17
6
votes
2 answers

SKPhysicsBody Collision Not Working

Below is my "Floor.swift" class below which is basically a bunch of walls. I have objects coming from the top of the screen and once the Floor and SKSpriteNodes collide, I'd like the SKSpriteNode to be removed. Below is my Floor class. import…
Dewan
  • 429
  • 3
  • 16
6
votes
2 answers

Swift 3 (SpriteKit): Locking the x axis of a SKSpriteNode and its physicsBody

I really need to know how to lock the x axis of an SKSpriteNode and its physicsBody. I need to keep the SKSpriteNode dynamic and affectedByGravity. The node is on a slope, so this is why it's x axis is moved due to gravity. However, I don't want the…
J.Treutlein
  • 963
  • 8
  • 23
6
votes
1 answer

SpriteKit: why node in collision has category bit mask of 4294967295 when this category was never assigned to a node

In the didBegin function below, one of the nodes has a category bit mask of 4294967295. However, this category is never assigned to any node. Here are all the bit masks in use: struct PhysicsCategory { static let None : UInt32 =…
Crashalot
  • 33,605
  • 61
  • 269
  • 439
6
votes
1 answer

My Physics Contacts are not making contact in SpriteKit

I am using Xcode 7.3.1, iOS 9.3 and Swift 2. Also tested on simulator and my iPad directly. I have done numerous searches, read 2 books of Spritekit Physics and watched numerous video tutorial as well as written ones. I have written body physics…
1
2
3
54 55