Adding gravity to an instantiated bullet....

UnrulyElf10UnrulyElf10 Posts: 37Member

Hi, I code in GDScript.
I'm making a game where you run around and throw nuts at enemies, and so far I've got the throwing nuts bit down- but the nut physics are a bit weird. They don't have alot- if any- gravity to them, and kind of float around and bounce off objects like they are in zero G. Just wondering if there was any way of making a couple of lines of code run when you instantiate a bullet, so that I can make the bullet dip and fall faster.


Tags :

Comments

  • DschoonmakerDschoonmaker Posts: 254Member

    What type of node is the bullet?

  • UnrulyElf10UnrulyElf10 Posts: 37Member

    It is a RigidBody2D

  • DschoonmakerDschoonmaker Posts: 254Member

    Hmm, that's odd. Are there any other rigid bodies in the scene? Do they have the same problem?

  • UnrulyElf10UnrulyElf10 Posts: 37Member

    No, there aren't any other rigidbodies in the scene. When I said zero G, they still fall down to the floor, but just really slowly, and can be thrown and bounce really high into the air

  • UnrulyElf10UnrulyElf10 Posts: 37Member

    I'm mainly trying to work out how I could make a few lines of code run when the nut/bullet is instantiated/ fired

  • TwistedTwiglegTwistedTwigleg Posts: 2,810Admin

    Copying my reply from the duplicate topic I accidentally replied to (I removed the duplicate):

    What node are the nuts using? If they are using a RigidBody node, you can adjust the gravity scale to increase how strong the gravity is applied. You could check if the RigidBody is colliding or not, and if it is not colliding, slowly increase the gravity scale (up to a limit) so it falls faster the longer its in the air.

  • UnrulyElf10UnrulyElf10 Posts: 37Member

    So are you saying if I put some code into the nut node, it will run it as soon as it is instantiated?

  • DschoonmakerDschoonmaker Posts: 254Member

    Is it possible you have an area affecting gravity, or maybe you changed the default gravity value(I think in 2D the default value is 98)?

  • UnrulyElf10UnrulyElf10 Posts: 37Member

    I'm pretty sure that I have no areas affecting gravity- but I may have changed the default gravity value. However, I wouldn't know because I don't know how to check. Also, all I want to know is that if I put some code into the nut node, it will run it as soon as it is instantiated? I think I can figure it out by myself after that :)

  • TwistedTwiglegTwistedTwigleg Posts: 2,810Admin
    edited August 2

    @UnrulyElf10 said:
    So are you saying if I put some code into the nut node, it will run it as soon as it is instantiated?

    You could adjust the gravity scale through code, or you could select the RigidBody2D node and adjust the gravity_scale property (documentation) through the inspector.
    Edit: The link to the documentation also explains where to go in the project settings to find the default gravity strength.

  • UnrulyElf10UnrulyElf10 Posts: 37Member

    Okay, that has worked. I turned the default gravity setting to 500 and the nuts are now falling much quicker. Thanks!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file