didBeginContact not called on fast moving sprite - ios

I have a game where a user is dragging around my main sprite. The main sprite collides with other sprites just fine except when the user drags the main sprite very quickly. Sometimes when the main sprite is moving quickly, the physics bodies just pass right through each other and the two sprites suddenly overlap. I have a breakpoint set that logs the hit count at didBeginContact, and it is not hit.
Is there a limit to how fast a sprite can move and still be covered by didBeginContact? Am I allowing the user to move the sprite faster than the game cycle can handle the collisions?
Again, when the sprite is moving at slow speeds, the physics are working perfectly.

Remember, these things are all calculated frame by frame. You're probably moving the sprite so fast that its ending up on the other side of the screen in too few frames to count as a collision. If someone is spastically moving their finger around it might not catch it. You could put some kind of speed limit on the sprite or something.

try to set physic body with usesPreciseCollisionDetection = YES

Related

Bouncing Ball SKPhysicsBody - Stop Bouncing Perpendicular Forever

So I'm making a brick break style game using "Ray Wenderlich's amazing tutorial" in Spritekit/Swift, just like the tutorial.
I successfully have a ball bouncing around the screen using a SKSpriteNode() and SKPhysicsBody() and I've been tweaking values for the impulses used to begin the ball bouncing around the screen forever.
However, I stumbled upon a problem which I hope to find a solution.
Sometimes, in my game, the Sprite will bounce around and become "Wall Locked" bouncing almost Perpendicular (or straight) between two walls, (give or take a few pixels)! So ends up Zig-Zagging across the whole screen between two said walls for ages.
What I want to do is, should this happen and the ball get "Wall Locked" to introduce a new impulse to get it moving again...
How can this be done? For example, if it has bounced between the top and bottom walls 10 times, then it's time to adjust it's angle/introduce a new impulse.
Could the last 10 positions be stored in an array, then test if their almost perpendicular somehow?
If you inspect the velocity property of your Sprite, you could detect when either of its values is close to zero and then make them something that is not so close to zero. This would stop it getting stuck moving just horizontally or vertically.

physicsBody.applyImpulse & collision happening twice instead of once

Heres the deal. My ball drops, hits the floor, and bounces back up with the help of the following code
ball.physicsBody?.applyImpulse(CGVectorMake(0, 25))
However, sometimes the ball recognises two collisions instead of one (on impact) and the ball gets applyImpulse x2. (Due to lag or something?) Causing the ball to fly way to fast. How do i make sure the ball doesn't collide with the floor twice? The ball is 16x16 an the floor is 16x160. I didn't have this problem earlier when the ball and floor were larger. But i really want to solve the problem and it must be possible!
What is happening is the ball is not moving fast enough between updates to be off the paddle before the next update check.
Remember what we did for the boss? Same thing gets applied to the paddle. When the ball hits the paddle, remove the contact check for it. Now you are going to have to add another node in, so that when you pass this node, you reenable the paddle check

Lag using SKAction

I've finished my game which uses the method + (SKAction *)moveToY:(CGFloat)y duration:(NSTimeInterval)sec to move sprites and when they collide with another sprite they disappear but when one of them collides with another object and disappears the other sprites that are falling down make some lag and I don't know if I could use another method to move sprites without lag.
PS: The sprites move a little bit fast(from y:0to y:568 in 0.5 seconds), is that maybe the problem?

Scrolling combined with physics moves my sprite out of the screen

I'm implementing a side scrolling game with SpriteKit:
As long as my sprite stays in the middle of the screen, I'm moving the sprite
When the sprite reaches the left or the right part of the screen, I'm moving the level instead of my sprite:
This works quite well, unless my sprite collides with another object. In that case the level (triggered by my code) and the sprite (triggered by the physics engine) are moved and the sprite moves outside the screen:
I tried to stop the impulse which is applied from the physics engine. This hasn't worked.
Any idea how to handle this?
Thanks
Stefan
I suppose by "moving the level" you mean moving the background view.
Why don't you just have an area in which your sprite moves that is the same size as your background? You can scroll to keep the sprite visible without disturbing the logic of physics and other manipulation of the movement.

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.

Resources