remove bouncing from PhysicsBody? - swift

How can I completely remove the bounciness from my PhysicsBodies, I already set the restitution of all PhysicsBodies to 0 but when multiple PhysicsBodies collide they still bounce off of each other, how can turn this off?
Here's a video where i swipe up and down which triggers this code on the blue SpriteNodes:
node.physicsBody?.applyImpulse(CGVector(dx: x, dy: y))
https://imgur.com/a/MD2Sc
I want the blue SpriteNodes to just stay up or down and not bounce away

Are you experimenting in a space without any world damping/friction? If so, you will need to zero the velocity of objects the moment they collide in order to get zero bounce. But you'll also need to move them outside the boundary of the objects they collided with.
By way of explanation:
This is, I presume, happening because your objects are achieving a (slight) state of overlap right before the collision is reported to the physics engine. When this happens, the first response of some physics engines is to remove this overlap by moving the object with a corrective amount of force or movement. What's happening looks like a continuation of that movement.
In some physics engines you get the opportunity to determine how strongly the corrective behaviour is, and how frequently it occurs, and even set the physics simulation to much higher rates of solving than the frame rate. In these engines you could find the right balance of settings to prevent this. But not in SpriteKit.

Related

SCNPhysicsBody calls contact delegate but does not make a collision at high speed?

I was making a test "breaker" game in SceneKit and tried speeding up the ball. At a certain point, the ball would consistently pass through my boundaries. Not quite sure why, I slowed down to 1 FPS and took this screenshot:
When looking at Apple's docs:
A small body might move so fast that it completely passes through
another physics body without ever having a frame of animation where
the two touch each other.
However, it is
clear that the ball is touching the boundary, yet still passes through. The contact delegate will also register a collision. This is with an x-velocity and z-velocity of 50-100 each. Shouldn't this scenario cause the ball to bounce back, as the frame rendered with the ball touching the obstacle? And along with this, how would I check super fast collisions as such in SceneKit? I heard that in SpriteKit, one can use usesPreciseCollisionDetection, but this doesn't seem to be the case in SceneKit.
To give an exact idea of what the boundaries look like, they are two cylinders with no space in between.
Edit: Seems like changing the physics shape on the boundary to either convex or concave instead of bounding box helps, but does NOT completely prevent a contact registering but a collision not happening. Same if I create a new obstacle - it'll pass through at high enough speeds while still registering contact delegate. Any theories on why?
Edit 2: From the comment on this question, here is a screenshot of where didBegin is called by setting a breakpoint. You can see that the ball is just leaving the barrier. It starts passing through when x-velocity or z-velocity is set to about 29-40 and is completely unreliable as to whether it passes through or not after that. Always though, didBegin is called, but not always didEnd

Detect collision for particles and Wind effect

I'm looking to achieve this effect.
I thought about making WIND PARTICLES and then when the player collides with it, force will be applied. But how can I check if the player collided with the WIND PARTICLES?
If you have other suggestions about how this effect can be achieved I will be more than thankful!
You do not want to do the collision test with particles, You want to use the SKFieldNode to achieve this effect.
https://developer.apple.com/reference/spritekit/skfieldnode
I am not sure which one to use for the wind effect, but at least it will get you started on the right direction, but basically what it does is set up a "force field" and the node hits this force field, some kind of physics get applied to it.

Unity Brick Breaker: Ball hitting in-between two bricks

I am making a 2D Brick Breaker game in Unity.
I have an issue with the scenario when ball hits in between two bricks. I have BoxCollider2D attached to all bricks and a CircleCollider2D attached to the ball. When the ball hits between 2 adjacent bricks, it bounces back in the same direction as if it hit the edge of the brick. There is no edge in between, but two adjacent bricks form a continuous surface. So, the ball should bounce off of the surface (in other direction) instead of bouncing back.
Anyone knows of any solution to tackle this problem? I asked this in the Unity Physics forums but didn't get any answer, so checking if anywhere here might have had this issue.
Thanks,
Mukul
I am guessing this could be the problem:
When your ball is hitting the bricks with a strong force, There is a chance it might move one of the bricks by a very very slight distance, even if the mass of the brick is much heavier.
This movement might cause an uneven surface, which is why the ball bounces back in the same direction.
Try adding a Rigidbody Component on every brick (if you have not done it already), and set its isKinematic property to true.
Let me know if this solves it.
Way 1:
Use one box collider for the wall, but not for every single brick.
This will fix your issue + will optimize your project.
Way 2:
You need to build wall programmaly and colliders in this case must be without spaces between them. This must fix the issue.
Way 3:
Make your own hitting wall logic.
OnColliderEnter you need to get balls velocity.
OnColliderEnd you need to set manually velocity.

Spherical rigid body will never stop rolling regardless of drag

My problem is that I have a rigid body with a spherical collider and once it starts moving (rolling) it never stops.
I have read other answers here which state that changing the drag (angular and normal) is the answer to this problem but I must be doing something wrong somewhere else. I have been experimenting with this for hours and cant find a solution.
I have moved the drag to a million, still moves but very very slowly. I have moved the angular drag to a million with similar results. I have set the sleepThreshold to a high number. This didnt seem to do anything. I tried changing the friction on the terrain.
I placed the ball on a flat, horizontal plane for all of these tests and applied an impulse to start it moving. It has never come to a stop yet.
There are times when it reaches a certain velocity and then stutters like it is about to stop and then it starts moving at a constant velocity forever, I think I can visibly observe the shift from deceleration to constant velocity. It doesnt make any sense to me at all.
It is my assumption that the ball should stop eventually and that unity, being so advanced, would handle this easily but its possible that I'm missing something due to being so new.

Spritekit how to not veer off

I'm building a pacman style maze game.
I can apply impulse and limit it to whatever vertical or horizontal direction as desired on the hero.
However, when I add physics body sprites for walls, it gets weird.
I have set the hero physics body and the walls to have no bounce.
Running head on into a wall it stops dead like expected.
But if I then change direction and move along the wall I veer off at a slight angle from the wall.
Any ideas what causes this and how to avoid it?
I want to only move in vertical and horizontal straight lines.
Ok so the solution here is slightly counter intuitive.
Rather than using applyForce: or applyImpulse: family of methods on the physicsBody, use runAction:forKey: on the sprite itself.
For any change in direction, removeAction:forKey: just before calling runAction:forKey: to keep things orthogonal.
(Otherwise there will be a brief angular movement )
The other trick here is to find an appropriate speed for distance. Too fast and it will fly through walls. (Bug?)
Then apply the speed and distance with a multiplier based on the size of your scene.
The total distance should be something greater than possible in any direction.
That keeps the thing moving until it hits a wall or you tell it to move in a different direction.
This works really well.
Using the physics body movement, it seems best suited to a platformer situation where you have a gravity.
In a top down view, there isn't normally gravity.
( though it is imaginable that you could want something that exerts gravity on a sprite to suck it in)