Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do i change gravity in code?

Discussion in 'Physics' started by FalsAlarm, Dec 25, 2016.

  1. FalsAlarm

    FalsAlarm

    Joined:
    Dec 12, 2016
    Posts:
    21
    I tried the following code but it doesn't work.
    Code (CSharp):
    1. Physics.gravity = new Vector3(-10,0,0);
     
    Last edited: Dec 25, 2016
  2. FalsAlarm

    FalsAlarm

    Joined:
    Dec 12, 2016
    Posts:
    21
    I just figured out the problem. My game is a 2d game so I had to use the below code to get it to work.

    Code (CSharp):
    1. Physics2D.gravity = new Vector3(-10f,0f,0f);