I’m very new to gdscript in general as well as coding.
So, I tried writing a movement code for a 2d sidescroller platformer, however the “is_on_floor” is returning only false even after the character is on the said floor, which just adds more gravity to the player making it unable to move, since it’s being pushed into the ground consistently every second (it’s every second, right?)
Anyway, I looked it up and many ppl said that you have to define the floor itself, however I really couldn’t figure it out no matter how I tried so I’m asking help from you, good people.
Here’s my code
extends CharacterBody2D
@export var gravity : float = 960.0
@export var speed : float = 300.0
func _process(delta : float) -> void:
if not is_on_floor():
velocity.y += gravity * delta
var direction := Input.get_axis("left","right")
if direction:
velocity.x = direction * speed
else:
velocity.x = move_toward(velocity.x, 0, speed)
move_and_slide()
I might’ve read your comment incorrectly, but making it -= instead of += just makes it subtract the gravity every second and the character just flies up endlessly. Also I didn’t really understand the second part of your comment regarding the column, could you elaborate please? Thank you!