Adding Force in Z direction to ship results in the ship rolling

Hello, I have a ship using buoyancy set up similar to this tutorial: How to Set Up Dynamic Water Physics and Boat Movement in Unity | Ship Buoyancy Tutorial - YouTube

Currently I am moving the ship by manipulating the position every FixedUpdate:

ship.transform.position += ship.transform.forward * speed * Time.fixedDeltaTime;

This is working fine, but the lever-to-ship-movement translation is very direct and does not feel realistic. That is why i tried to use the AddForce method of the Rigidbody of the ship:

ship.GetComponent().AddForce(ship.transform.forward * speed, ForceMode.Acceleration);

The speed is a lot slower, but this can be fixed. My problem is that my ship begins to roll around the Z axis as soon as I get faster. I have experimented with different ForceModes, multiplying Time.fixedDeltaTime and more. Only the exchange of this one line of code seems to make the rotation difference. Am I also adding force to the rotation when using AddForce()? I don’t really get it…

ok firstly it should be ship.GetComponent<Rigidbody>().AddForce

The ship is rotating because of the physics of the friction between it and the water caused by the buoyancy. if you have a ball sitting in a bathtub and you push it to the right, its not going to just move in that direction without rotating at all. if you want to make it stop rotating you could freeze the z rotation on the rigidbody or (better idea imo) use position and Vector3.SmoothDamp to make it smoot

Provide variables Vector3 velocity; and float smoothTime; decreasing smoothTime makes the movement faster.

ship.transform.position = Vector3.SmoothDamp(ship.transform.position, new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")), ref velocity, smoothTime);
if this doesnt work then, idk sorry ig

Thanks for the fast reply @CyplexGaming ! I Didnt even think about the friction. Maybe it really is a better idea to not use the force physics and adjust the position change :slight_smile: I will let you know if it worked.