Am new to gd script

godot-4

	velocity.y+= gravity() * delta

thats the code am having issue with ,and the error finder or whatever in the bottom
Function “gravity()” not found in base self.
sorry am new to pc i swear

When you add a script to a CharacterBody2D it will add a gravity var at the to of the file.

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

Also, gravity is a variable, not a function.

velocity.y += gravity * delta
2 Likes

How do i change the grivity with code

ProjectSettings.set_setting("physics/2d/default_gravity", 1.42)

That isnt working for me. this is my code

never mind i just saw that im using 2d gravity for my 3d game

double nevermind still not working

Weird;

Is pretty simply stating it changes the settings. I have never used that method, so I don’t understand why it wouldn’t work right out of the box.

What does it print if you used get_setting() right after the call, did it change it there?

The API has a save() but that is for external saving.

you can also set a new gravity variable and use that one. if you want the gravity to effect every script then you can create the variable in an autoloaded script.

1 Like

Yeah i had it print out the results and the first part of the code is working but the second half doesnt work it will only print 9.8 i will update once i have tried the gravity varible thing that Locklan mentioned

ok update i forgot to add the second print so thats why i only got the one thing. heres the output from one jump
Screenshot 2025-02-23 191623