Stopping a Rigidbody from floating

I’m currently having a rigidbody be suspended in the air for a game that consists of ships, and not in space. But on Earth. How I am suspending the object in air at a constant is putting one line of code in the Update function. Although of course more of the Update function is being used as controls.

this.transform.position.y = shipAltitude;

shipAltitude has a integer of 20.

I have used force and velocity to override the Rigidbody stuff. When a control is pressed a boolean value “movement” is set to true, and when control is not in use. The variable is set to false. Though I set an if or else statement as this.

if (movement == false)
{
velocity = 0.0;
force = 0.0;
}

Right now I have the following variables in from above. I tried using ‘this.transform.position.x = xSet’ which the ‘xSet’ variable consisted of ‘transform.position.x’. Which of course didn’t really do anything when you think about it. Would magnitude override whatever is controlling the rigidbody?. Here’s an ideal of what the object is doing.

It has a box collider with a rigidbody. The ship is then colliding into a building or bridge and it slowly ricochets off and slowly drifts away from the building or bridge.

A Couple of pointers. when working with objects controlled by physics you are best to use the FixedUpdate method to apply forces. This will ensure your game simulation runs the same on other hardware.

An alternative to hard coding the y position each frame is to add a configurable joint to your ship that locks movement on the y axis.

Lastly, I don’t know if you’ve played with the Physics Material system yet, it sounds like the objects have too much bounce or your ship doesn’t have enough drag which would slow it down.

Actually I never have messed with the Drag variable, which help very much in slowing down the object from bouncing off of other rigidbodys (buildings, bridges, enemys, etc).

I never knew what a Confirgurable Joint was, I have to read more in depth with that. Since it has many features in controlling an object.

The Physics Material sounds quite complex, I might read more in depth with that aswell. And also knowing the pointer for the FixedUpdate function that you gave, I will use that more than the Update function itself, thanks a lot Devan.