Gravity code isnt working

I am very new to godot and game dev in general i am trying to make the player fall 3x as fast as the default gravity here’s my code:

Sadly changing the project settings does not affect the value after the game launches. I don’t think you want to change the overall gravity either though. If you could share how you are applying gravity, either from get_gravity() or a var gravity near the top of the script.

Then you can apply more speed if the action is pressed

if not is_on_floor():
    if Input.is_action_pressed("ui_down"):
        velocity += get_gravity() * 3 * delta
    else:
        velocity += get_gravity() * delta

The if statements above are also suspicious, if your intent is to only rotate when right or left is pressed you should use Input.is_action_pressed, and you can chain these together with or if you want more available actions, but you should use your own actions from the Project settings “Input Map” tab; instead of ui_* actions.

if Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_text_scroll_down"):

You could also use get_axis, again preferably using custom actions

var rotate_amount: float = Input.get_axis("turn_right", "turn_left")
$MeshInstance3D.rotate_z(rotate_amount * 0.15)
$GPUParticles3D.emitting = is_zero_approx(rotate_amount)

Make sure to paste scripts instead of screenshots

Huh, that would be nice to have in the docs, if it’s there I am blind. :laughing:

It does, nearly every project setting has this warning

Note: This property is only read when the project starts. To change the default gravity at runtime, use the following code sample:

docs.godotengine.org

You will see this if hovering over the option in the Project Settings.

Though I guess if you use ProjectSettings.get_setting it would be changed, but not the gravity the physics server uses.

I didn’t look at the actual setting descriptions, I was scanning, so yeah I was speaking of the set_setting() doc at speed read.

My bad for not reading the whole page this time, I love it when that happens. Not very much but did this time, idiot moment. heh

No the product has failed you, machines are built to serve not feel stupid. There should be a similar warning in set_setting.

2 Likes

thanks for the help with the other if statements i have the text_scroll inputs in there because i am trying to disable foreward and backward movement

so i plugged this in and im getting a error about delta

i have no idea what delta is so an explanation would be very helpful removing the delta from both instances seemed to work but i dont know what they are or if they are important

This is why I don’t like having a seperate get_input function. _physics_process has delta, but you’ve made another function that doesn’t take any parameters such as delta. You will have to either add it as a parameter or move your code to it’s place in _physics_process.


Make sure to paste scripts instead of screen shots

Ok thanks for the tip
Update: having the delta just removed the gravity increase so i removed it and it is working fine