Search Unity

Different gravity settings

Discussion in '2D' started by plapi, Apr 18, 2019.

  1. plapi

    plapi

    Joined:
    Apr 18, 2019
    Posts:
    6
    Hey Community,

    I am trying to make a little "test-game".. I want to do a platform, which is moving up (so far, I did it per Rigidbody2D, and then just changed the Gravity settings in 'Edit' -> 'Project Settings...' to x:0 y:3) and a character which has normal gravity (x:0 y:-9.81).

    Is there any way to create special gravity settings for my platform?


    I am really happy about a helpful answer, because I tried this the last hours but I couldn't figure out how to do it ;)

    I am using Unity 2018.3.6f1 Personal
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,462
    What exactly do you mean by changing the gravity of the platform? Like, interacting with the platform changes the character's gravity? Or, the platform itself is affected by changing gravity? Anyways, I use this for my gravity changes: https://docs.unity3d.com/ScriptReference/Physics2D-gravity.html

    Note: You can change the value of the Vector 2 to whatever you wish, -9.8 is just closely simulating normal gravity.
     
  3. plapi

    plapi

    Joined:
    Apr 18, 2019
    Posts:
    6
    I want two different gravity settings for two different objects, so for example one is x= 0 y= 2 and the other one is x= 0 y=-2
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,462
    Just try:
    Code (CSharp):
    1.  Physics2D.gravity = new Vector2(0, 2);
    2.  
    3. //Other gravity
    4. Physics2D.gravity = new Vector2(0, -2);
     
  5. RockyWallbanger

    RockyWallbanger

    Joined:
    Mar 16, 2014
    Posts:
    85
    Cornysam likes this.