I am having problems with the gravity at 1st i thought it was my code so i tried a couple of tutorials to see theirs and nothing worked every single time i apply gravity my character gets stuck in the ground, also for example if i lower the gravity and character moves it still says is_on_floor() = false if anyone can help me i`d appreciate it.
just make a character 2D(parent)node and make a sprite as a child and go click to the parent and add a script.before you add it,change the template to basic movement and godot will make a script with gravity and movement functions in it for you
extends UniversalEntity
@export_category("move_vars")
@export_range(0,100,1,"or_greater") var speed := 100.0
@export var acceleration := 700
@export var friction := 900
@export_category("jump_vars")
@export_range(0,100,1,"or_greater") var jump_strength := 300
# delta is the current frame time aka at 30FPS ≈ 1/30 ≈ 0.0333s etc.
func _physics_process(delta: float) -> void:
# Player movement for left and right
if direction.x:
velocity.x = move_toward(velocity.x, direction.x * speed, acceleration * delta)
else:
velocity.x = move_toward(velocity.x, 0, friction * delta)
_apply_gravity(delta)
move_and_slide()
## Checks if a jump is possible
func try_jump() -> bool:
print(is_on_floor())
if is_on_floor():
_jump()
return true
return false
## Executes a jump
func _jump():
velocity.y = -jump_strength
put the tile map in to the main scene and also the player,then go to tilemap then tileset and go to draw(before that go to the tilemap inspector and make a physics layer)select the property editor “physics layer 0” and paint blue squares to the tiles,then save and go to tilemap to paint tiles into your game like i was doing an hour ago