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

categoryBitMask Returning UInt32.max

I am working on a game with a variety of collisions. I have created an Enumeration as follows: enum CollisionCategories: UInt32 { case localPlayer = 1 case ball = 2 case remotePlayer = 4 case scene = 8 case goal = 16 } I then…
Kendel
  • 1,698
  • 2
  • 17
  • 33
-1
votes
1 answer

Accelerometer not working when setting Player.physicsBody!.dynamic = false in swift

I am new in spritekit and trying to develop a game with Acceleromotion restricting the SKSpritNode going outide the screen.It is working fine when I set the Player.physicsBody!.dynamic = true but same code is not working when setting this property…
-1
votes
4 answers

Can I have physics bodies collide without pushing each other?

I have a game made of little SKNodes moving around. They can not overlap, so I use physics bodies, so that they move around each other. However, in the case that one sknode is animated to follow another, it pushes the sknode ahead. Setting the…
Michael
  • 1,115
  • 9
  • 24
-1
votes
2 answers

Can't disable physics in Sprite Kit

I have two nodes one near another. And I want one node to be on top of another when I tap. I do so like this: SKAction *moveUp= [SKAction moveByX:0 y:25 duration:0.1]; SKAction *moveDown= [SKAction moveByX:0 y:-25 duration:0.1]; SKAction…
HelloimDarius
  • 695
  • 5
  • 23
-1
votes
1 answer

Objective C - SpriteKit - Unable to detect contact between ball and paddle node

I am trying to detect the collision between the ball node and either one of the paddle nodes but the message to confirm the collision is not being fired. Could somebody help me understand where I am going wrong? //categories for detecting contacts…
-1
votes
1 answer

How to set physicsBody for doting image?

When I set physicsBody to image with full circle it works fine! LIKE : sprite.physicsBody = [SKPhysicsBody bodyWithTexture:sprite.texture…
Sambha
  • 1
  • 4
-1
votes
1 answer

How to draw a path using NSMutableArray elements which are CGPoint

I'm new in Objective-C developing and I'm working on project that uses SpriteKit. I'm trying to create a scene that contains an arena with corners as controlPoints. my code is as below: MyScene.m: -(id)initWithSize:(CGSize)size…
Guizmoo03
  • 660
  • 1
  • 7
  • 23
-1
votes
1 answer

Sprite Kit physicsBody loses consistency during rotation - zrotation

I have this classic situation of a pinball game All objects are physicsBody with rights collision masks and so on.. they collide perfectly. The problem is that they only work when they are static...If I try to rotate a paddle on its anchorpoint,…
-1
votes
2 answers

How to apply constant force to sprite?

I have a sprite that I want to apply a constant force to, as opposed to reapplying that force every update, which is giving me strange results. I have a sprite that has a mass of 60 kg and is affected by gravity. I want to apply a force that is…
michaelsnowden
  • 6,031
  • 2
  • 38
  • 83
-1
votes
1 answer

How to create a semi-circle Physics Body by using sprite kit

I'm creating a semi-circle node when i try to develop a simple sprite kit game, but i wish the physics body of the node just cover the circle object's edge, and the physics body rotates with the circle(to change the physics body programatically),…
luckyee
  • 157
  • 1
  • 1
  • 15
-2
votes
1 answer

Are sprites automatically removed?

I'm currently trying to code some falling stars in my game, and they seem to disappear once they move out of the screen. But I'm not sure if swift is actually automatically deleting for me, or if they're still lingering around. I'm starting them at…
Shisui
  • 1,051
  • 1
  • 8
  • 23
-2
votes
1 answer

Can't add impulse or velocity to physics body without game crashing

I'm trying to make it so that my sprite receives impulse and velocity when a touch is made somewhere on the screen, but I get the error code: fatal error: unexpectedly found nil while unwrapping an Optional value It is forcing me to put a "!" in…
Jacob
  • 91
  • 1
  • 7
-2
votes
1 answer

How do can I make things collide and do things when they do?

I have been trying to do this for ages, what I would like to do is, I have a rocket and missiles coming down in my Scene and I want a very very simple explanation on how to do this so when the missiles collide with the rocket it will run a function…
-3
votes
1 answer

Swift programming. Possible problem with SKPhysicscontact

I'm working on a project / game and I'm stuck at adding new enemies to the game and to program them. This is how my code looked before I started changing and only had one type of "alien". I want to create two new types, one that you lose 5 points…
-3
votes
1 answer

Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

I get the error for the line of code here: override func touchesBegan(_ touches: Set, with event: UIEvent?) { hero.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 300)) } I'm quite new to code and I am having trouble working out why I am…
Nemo
  • 3
  • 2
1 2 3
54
55