Spritekit Physics in Swift - Ball Slides Against Wall Instead of Reflecting

Make a moving physics body collide with others without being affected itself

All you have to do is to set the collisonBitMask of the other body to include the categoryBitMask of the body you want to be unaffected, and then make sure that the collsionBitMAsk of the body to be unaffected does NOT include any of the categoryBitMasks of the bodies that it is not to be affected by.

It will then happily smash everything out of it's way /p>

Swift + Physics: Wrong angle calculation on collision

Since i cannot imagine this is some unknown bug in SpriteKits physics engine, 
i very hope someone can help me here as this is a full stopper for me.

It is a (known) bug in SpriteKits physic engine. But sometimes just playing with the values will make this bug disappear - for example, try changing the ball's speed (even by small value) every time it's hitting the wall.

Another solutions are listed here:
SpriteKit physics in Swift - Ball slides against wall instead of reflecting

(The same problem as yours, already from 2014, still not fixed..)

outline of physics body is showing through all other nodes in my swift SpriteKit game

There is a flag, which when set, allows you to see the physics bodies. This is useful for checking collisions etc.
In GameviewController, comment out view.showsPhysics = true. So

//view.showsPhysics = true

SpriteKit ball loses all energy hitting wall, restitution=1

When the collision velocity is small enough (such as your CGVector of (0, 0.5)), Box2d underlying the Sprite Kit physics engine will compute the collision as inelastic (i.e. as if the restitution was 0, removing any bounciness), and the node will not bounce.

This is, per the Box2d documentation, to prevent jitter.

In the Box2d source code, you even have this line:

/// A velocity threshold for elastic collisions. Any collision with a relative linear
/// velocity below this threshold will be treated as inelastic.
#define b2_velocityThreshold

Your impulse should be above this threshold for the restitution to be respected.

Masking and Physics in SpriteKit

SKCropNode only pertains to how a node appears on the screen, it does not deal with physics bodies. You can however use SKPhysicsBody(polygonFrom:CGPath) to create a path that is identical to the body you are trying to mimic, with the gap and everything. I recommend using the program PhysicsEditor to achieve such effect. https://www.codeandweb.com/physicseditor



Related Topics



Leave a reply



Submit