Changing the speed at which an object drops when affected by gravity.(SpriteKit) - swift

I have an object that needs to fall down the scene when the game starts. When the player taps the screen the object moves back to the top of the scene. In order to make the object fall I set it to be affected by gravity. This works fine but the problem is the object falls down the screen to fast. Can I set the speed at which the object falls do to gravity to a different speed. If so how do I do this.

You can reduce the gravity of the physicsWorld. Another option is to apply a force in the opposite direction to each object. If the gravity is -9.8 in the y axis, you could apply a force from +0-9.8 in the y axis to slow the object down.
EDIT: Changing the mass does not affect the speed.

Related

How to get rid of acceleration during bouncing ? (unity 2D)

I don't know if this is the correct therm, but I want to get rid of any kind of forces that could modify the speed of my object. Let me explain : the game is 2D top-down view and the character fires a bullet that bounces x amount of time, WITH CONSTANT SPEED. Everything works fine, but when the bullet bounces fast and many times, its speed increases.
Also, second problem: I have a rotating object and when the bullet hits it, its speed increases (which makes sense, but I would like to know if there is a way to delete this effect) .
I would like to know if there is a way to solve my issues.
You need to check the material of the object for your first question (https://docs.unity3d.com/Manual/class-PhysicMaterial.html) you need to set Bounciness to 1 so it will maintain dame speed. If you set it to 0 there will be no bounce and probably you have a value bigger than 1 and so it's increasing.
In the second case it's all about the forces involving. The object bouncing on the rotating one is adding a force to that one. If you want to keep the second one with same rotation you could rotate it with a transform.Rotate and remove a Rigidbody or set it to static

How to stop my ball from bouncing in Y asis unity

I want to make a ball that bounces back from walls and hurdles but doesn't bounce in Y-axis. Is it possible I am currently applying force whenever the ball leaves the ground but it is not giving a realistic effect
I thought there were checkboxes in the inspector to lock an axis... either way, you could cache the previous Y value in fixedUpdate() as "lockedY", and if the current Y axis value is higher, just reapply the cached one, I think.

SpriteKit move node with physics rather than updating position

My main character moves by touching and holding him and then moving your finger left or right to move the character. To do this I just simply update the node's x position (walks left and right on a flat surface) in touchesMoved() with the x position of the touch location, and apply an animation depending on the direction he's moving.
I want to kind of take this to the next level and accomplish the same effect, but using physics, so that when I'm done moving him and release my finger, he may slide a little bit in the direction he was moving given the speed I was moving him at, if that makes sense. Does anyone know how I can accomplish this effect?
Would I have to do as I'm currently doing and update the position as it moves, but also apply a force/impulse at the same time? Kind of confused on how to approach this
Moving the physics body via force, impulse, or velocity will automatically update the player position.
So you will have to play around with the correct way to accomplish your goal. But based on this, what I would suggest is replace your .position code with .physicsBody!.velocity code in your touchesMoved. Then, on your touchesEnded, you can apply a bit of an impulse to give the player that little bit of an "on ice" effect to keep them going a tad.
You will need to experiment with how much velocity you want to get the character to move at the correct speed, and then you will need to play with the impulse figures as well to get it just right.
This could get a bit tricky though, in touchesMoved... because at some point you will want to reset the velocity to 0 (so they stop moving when your finger stops).
To do that, you will need to to use the .previousLocation from your touch object, and compare the distance of X moved. if the distance X moved is >0 (or some deadzone threshold) then apply the velocity; if the deltaX is 0, then set the velocity to 0.
This may actually be more complicated than just using .position to move the character, then having the character slide a bit with physics on touchesEnded.
You will have to play with it to get it right.

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.

Box2d SetLinearVelocity not working with gravity

I have a body (player) in my box2d world.
Whenever I try to set its x velocity (every 2 seconds or whatever) and it is falling due to gravity, it jitters up and down.
I have also tried to set its y velocity equal to gravity (-30.0f) but then it does it even worse.
Tyvm.
That's because you player is created as a dynamic body. So the gravity is applied to the player every simulation step causing he/she to change the velocity.
Put your player b2_kinematicBody - then no forces will be applied to it. If you still want the player to be dynamic apply force -playerMass*gravityVector each step (or set autoClearForces parameter of b2World to false and apply force once) to remove gravity force.