Unity Physics: Gravity Controls

Jared Amlin
Nerd For Tech
Published in
3 min readAug 13, 2024

--

When it comes to using the physics engine in Unity, gravity basics can go a long way toward achieving a variety of behaviors.

Gravity

I am going be using this sci-fi crate object for this example. It has box collider and rigidbody components.

By default, Use Gravity is enabled on the rigidbody, which will use Unity’s default gravity settings.

The Project Settings > Physics directory will show where the default gravity value is stored. It is a Vector3 variable that applies downward movement on the Y axis.

This Gravity script is attached to the cube object, and has a Vector3 variable with a positive 1 value on the Y axis. Using this value will make objects float upwards with a small amount of reverse gravity.

Physics.gravity is assigned the value of the simulated gravity variable in void Start.

public class Gravity : MonoBehaviour
{
[SerializeField] private Vector3 _simulatedGravity;

// Start is…

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Jared Amlin
Jared Amlin

Written by Jared Amlin

I am an artist and musician, that is currently diving headfirst into game development with C# and Unity3D.

No responses yet