Make a certain sprite ignore SKPhysicsBody - ios

I am having an issue making a sprite ignore the effects of a SKPhysicsBody placed as a ground platform in an iOS project. I have only one sprite that I would like to "follow the rules" of the SKPhysicsBody and for all other sprites to "pass through". I have searched for a way to do this, but to no avail. Any suggestions?

for any physics body that you want to pass through set its collisionBitMask to 0 that means that it won't collide with anything, make sure you don't set the collisionBitMask of the ground to the type of sprite you want them to pass through,

Related

SpriteKit categoryBitMask issue

I'm new to Spritekit, and I'm having some trouble with something simple.
I'm making a pinball game. In order to detect collisions and award points with the ball, the bumpers have the following set:
categoryBitMask
collisionBitMask
contactTestBitMask
However, once I set categoryBitMask, the object no longer acts the same way. The ball passes through the bumper.
I've tried to set the properties in code to mirror what is set in the SKS file:
physicsBody?.isDynamic
physicsBody?.affectedByGravity
physicsBody?.allowsRotation
physicsBody?.pinned
physicsBody?.mass
But this doesn't make any difference.
How can I make a SKSpriteNode maintain it's physical properties after setting the categoryBitMask?
I found the issue. I was setting the collision on one object but not the other
ball.collisionBitMask = ...contains bumper
ball.contactTestBitMask = ... contains bumper
but not the bumper:
bumper.collisionBitMask = ...didn't contain ball
bumper.contactTestBitMask = ...didn't contain ball

volume-based physicsBodies being moved manually not contacting edge-based physicsBody

So in my Space Invaders game, all collisions were working perfectly until I added a physics body created from a edgeChainFromPath which is a single line to represent the ground (an SKShapeNode created from 2 points). Now my invader bombs (which move via SKAction) notify when they hit the ground but my invaders (moved in update() by manually updating their positions) do not. My ship missiles (also moved by SKAction) DO notify when contacting an invader.
Question : if a physicsBody is moved manually and comes into contact with another physicsBody, is didBeginContact not called? (All physics interactions - bitMasks, delegates etc - are set correctly). I'm thinking the answer is 'No it's not' because that's the only explanation and makes sense picturing how Sprite/Kit probably works. I.e. A contact occurs when the SK engine itself moves a node and realises that it's physicsBody is being drawn on top of another physicsBody.
Edit - just realised that I have other physicsBodies in my scene that are stationary and that the invaders DO collide with, so it's not an SKAction thing. The difference might be that the new node I've added is an edge-based body belonging to an SKShapeNode, rather than a volume-based body for a SKSPriteNode, but nothing in the documentation that I can find states that this shouldn't work.
New question : Do volume-based bodies being moved manually not collide with stationary edge-based bodies?
Ok - my bad. The invaders' physicsBodies had dynamic=false. Every other sprite was dynamic, so all other collisions were working. My new shape was an edge-based body which also are dynamic=false.
Made that one change and all is Ok. I need to update my checkPhysics() routine to test for this.
Edit: I really should have seen this earlier - checkPhysics() was not printing that invader notifies when contacting ground, which I just put down to a glitch that I'd fix later. Whereas checkPhysics() deliberately doesn't report on nodes with dynamic=false. I think that when I wrote the function, I assumed that you'd set dynamic=false deliberately to not be involved in collision/contact detection. I should change it to print a warning.

iOS Sprite Kit Collision with movement through elements

Is it possible to use Sprite kit's physicsBody to have element collision and still allow elements to go through each other? I'm interested in having the delegate to be called only when two borders hit each other and then allow them to go through each other afterwards :)
Yes this is possible. You can register for callbacks from collisions between objects but not have the collision affect the object itself.
The Ray Wenderlich - Sprite Kit book explains how to do this in the Zombie Conga game tutorial.
Try this one... http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners
The section called "Collision Detection and Physics: Implementation" should explain what you need.
Just had a quick read and the two things you're after are...
contactTestBitMask this is which object collisions you want to receive collision callbacks for.
collisionBitMask this is which object will collide and "bounce" off each other.

How would I build pool-cues / simplified pinball-style plungers with SpriteKit?

I'm working on a game in which the user should be able to trigger 'rods' that come out from the edge of the screen to displace elements on screen (balls). These projectiles roughly resemble pool-cues. Or perhaps pinball plungers, except that they start from the 'loaded' position (mostly offscreen), and when triggered, they eject out, then quickly retreat.
I'm unclear how I should build these with Sprite Kit.
The game uses the PhysicsEngine, and the onscreen balls should be effected both by gravity AND they should be displaced when they collide with the rods. However the rods should neither be effected by gravity, not displaced when they collide with the balls -- they should simply retreat regardless of whether they've made contact with the balls.
I realize I can set the affectedByGravity property for the rods. However because they will still displace slightly when they collide with the balls. How can I 'fix' or 'peg' them in place? Do I need to use an SKPhysicsSlidingJoint? If so, has anyone encountered any examples online? Is there a simpler way to do this?
A related physics engine, Box2D distinguishes static, kinematic, and dynamic bodies.
Kinematic bodies can move and will collide with other objects, but they are themselves not affected by dynamic bodies or forces like gravity. Thus, consider setting rod.dynamic = NO; but animate it with actions. See also here in the reference for SKPhysicsBody.

CORONA SDK Physics that dont affect every sprite

I want to make some sprites affected by physics gravity, but not all of them in the display screen. For example, the player don't need to be affected and, when collision with another, this one leaves another sprite object that will be affected.
Sorry for my english i'm foreign and try to explain better I can do.
Thanks!!!.
Check this thread out,
Collision Filtering
or check for collision filtering and masking bits.
Are you looking for this?
http://docs.coronalabs.com/api/type/Body/gravityScale.html
Setting gravityScale for a physics body to zero makes it unaffected by gravity.
myObj.gravityScale = 0
Setting it to a negative value makes it "float", for example if you want a balloon going up :)

Resources