Small, "bouncy" lags when pushing an SKShapeNode with another shape moved by an SKAction - swift

I am creating a 2D autoscroller and when my player (with a circle physicsBody) collides with an SKAction moveTo-powered obstacle which is moving towards it, it makes small, almost unnoticable lags. I tried lowering the friction and the density of the objects, but nothing helped. Any ideas?

You have chosen to use a circle with phycsicsBody. 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. After the scene completes these calculations, it updates the positions and orientations of the node objects.
You have also chosen to use SKActions, when using the actions to move a body such changes don't go through the physics engine, indeed usually you could add unwanted actions and unexpected events as "bouncy lags".
So, if you're using physics to move a body, you shouldn't use move actions, apply an impulse or force, or set it's velocity directly

Setting restitution to zero may help. This controls the elasticity, or bounciness of a sprite.

Related

Unity: Fish with rigid body leaving water

I am making a simulation of some fish in a lake.
I am using rigid body as otherwise they move through the sides. But when they hit into the sides they rotate and then the script I have to set their rotation to 0,0,0 when they leave fails.
Your problem may be occurred by the fact that you are using unity's physics to move the fish but trying to set rotation directly. In this case movement and rotation of the fish are driven by Physics and forces, applied to the object. But you still can affect rotation and position if you reset all forces. Try looking here to learn how to remove forces.
Also when dealing with Physics in Unity, don't mess Update() and FixedUpdate() methods, because it may lead to an incorrect result.
When you say "hit into the sides" do you mean the sides of the simulated lake?
If so, one option might be to set the objects that denote the sides as "kinematic." Then you can detect when a GameObject (such as a fish) collides with it but it won't cause any physics reaction.
(ref: RigidBody)

SKEmitterNode explosion with force to another Object

I've an explosion in my SKScene and I want this Explosion even effect another objects close to its , Object are in all sides .I want to give them force to run away with this explosion .
It sounds like you need an SKFieldNode implementing a vortexField():
https://developer.apple.com/reference/spritekit/skfieldnode#1654415
SKFieldNode:
A node that applies physics effects to a portion of the scene.
vortextField()
Creates a field node that applies a perpendicular force to physics bodies.

SKPhysics in Swift - Lowering Speed Property Jittery

Usually in 2D physics engines like JBox2D, if the user wanted to make a simulation run in "slow motion", you would just decrease the value by which the simulated world iterates by, for example normal movement at 60fps, the step would be 1/60 if the physics world is stepped forward every frame.
But for the SKPhysics class in the sprite kit in xcode 6 using swift, I only see the property called ".speed" which when I decreased, only led to a jittery mess, that updated the physics bodies once every 10 frames.
Is there a specific property, or trick maybe to get the SKPhysics world to iterate forward in time by smaller increments without gross glitchy movements?
The only way to slow down the simulation in sprite kit is to use the physicsWorld.speed element.
But if you are trying to change only one or two sprite speeds, try the velocity element of the sprite:
node.physicsBody.velocity = x
you can directly change the velocity(speed) of your node or sprite through its physicsBody.
Hope it helps :)

Unity: Ball falls through object that is rotating around another object

Imagine you have a ball falling due to gravity. When it encounters a rotating "cube" object, then you would expect it to bounce off of the object. However, in my case if the cube is rotating fast, the ball goes through it, but if the cube is rotating slowly, the ball hits it and bounces away as expected.
I am using RotateAround() inside the Update() method to achieve the "cube" object's rotation. I tried setting the ball's collision detection to Discrete, Continuous, and Continuous Dynamic with no luck.
My goal is to make the ball bounce away no matter how fast the "cube" object is rotating around another object.
Is there something else I should look into?
Thanks!
You can try lowering the Fixed Timestep value under Edit > Project Settings > Time.
Be aware that this will affect the performance of the game as you're calculating physics more often.
Documentation: http://docs.unity3d.com/Manual/class-TimeManager.html
Also, I assume that you have box and sphere colliders as opposed to mesh colliders? The former are more efficient at detecting collisions.

Physics vs graphics fighting each other (box2d)

so I have a ball (sprite subclass) that can be dragged around the screen and updates it body to tell the world its position.
The problem is, when I apply a force to the ball while the ball is being touched (thus being controlled by a finger), I have two pieces of code fighting against each other to update the sprite's visual position.
The world stepper is trying to follow through the physics and update the ball's position. The touch methods however are also trying to update the ball's body and graphic position. Ideally, when touched I would like to kill off any physics affecting the ball.
So what exactly should I be trying to do to consolidate this? This is also creating issues for collisions and filtering. Any help appreciated. Thanks
Do you want the ball to have an accurate physics simulation? If not, you could always use the SetTransform method of the b2body class like this.
CGPoint ballLocation = ;//use the touched location for this
b2Vec2 vecBallLocation = b2Vec2(ballLocation.x / 32, ballLocation.y / 32);//calculate this on your own
b2Body * ballBody = ;//replace this variable with your ball's b2Body;
ballBody->SetTransform(vecBallLocation, ballBody->GetAngle());
Do not set the ball sprite's position manually. Leave this up to the physics simulation. Your code will get really messy over time if you have to keep track of what sprites you set the position of manually and which ones use the physics simulation to update their positions. This way is also much easier.
When the physics object is being dragged, set its velocity and angular velocity to 0,0 before running the physics step simulation. You may also want to temporarily get the physics object's position, then step, then set the body's position back, then apply whatever touch dragging offset you got from moving the finger to the body.