1. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Change gravity of objects

Discussion in 'Modding Help' started by Asu, May 8, 2013.

  1. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    How to change the gravity of objects ( If possible, changing the gravity only for a crate for example )
     
  2. VanHuek

    VanHuek KAG Guard Tester

    Messages:
    751
    Gravity is relative so how would you propose to do it to one object?
     
  3. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    By always applying (-gravity) ? But I don't know how.
     
  4. Probably better ways of doing this but, you can use the addForce(Vec2f); method to apply a downward force similar to gravity.

    Just find a tick method or something similar that's called every tick and place this.addForce(Vec2f(0.0f, 10.0f)); into it. (The y float should be positive to make it go down)

    The biggest example of this being used is in the generic Vehicle class. It's used for movement based on the player's input.

    I didn't actually test it, and all this is based off memory but I think it's possible that way. I can't think of a way to affect the gravity directly, try making it way more? :/
     
    joshua12131415 and kaizokuroof like this.
  5. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Aaargh I know nothing to vectors.. But I'll try, thanks.
     
  6. Vectors hold an x and a y value, in this case a float. You're using it this time for 2 speeds, the downward speed, and the horizontal speed. The greater each value is the faster it will go in that direction. A grid in KAG starts with 0,0 in the top left

    0,0-------------------------------
    |
    |
    |
    |
    |
    |
    |
    | ----------------------------10,10


    If I wanted to go from 0,0 to 10,10 I could enter a Vector of (1,1) to go 1 space down and 1 space right per tick.

    To go back I could enter a (-2, -2) to go up 2 spaces per tick, and left 2 spaces per tick.

    So if you wanted to make a boulder that floated in the air, you would want to have a vector that tells it to go up about the speed of gravity (I think it's like 10.7 or something (It's been awhile since I made airships)) so you would give it a force with a vector of (-10.7f, 0.0f)
     
    joshua12131415 likes this.
  7. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Okay.. I'm 12 but I understood almost all. So it is a bit addForce(Vec2F(VerticalSpeed,HorizontalSpeed)). So then addForce(vec2F(-10.7,0)). But where do I need to insert this line of code, for example in the boat?

    There?
    Code:
        Vehicle_Setup( this,
                       135.0f, // move speed
                       0.19f,  // turn speed
                       addForce(vec2f(-10.7,0))
                       Vec2f(0.0f, -5.0f), // jump out velocity
                       true  // inventory access
                     );
     
  8. VanHuek

    VanHuek KAG Guard Tester

    Messages:
    751

    It isn't speed.... but velocity.


    [​IMG]