0 votes

my charakter falls too fast (2d platformer):

extends KinematicBody2D

onready var screenshaker = $Camera2D/screenshaker
var move = Vector2()
var speed = 200
var jump_speed = -300

var gravity = 10
var lastdir = 1

func physicsprocess(delta):
move.y += gravity
move.x = (Input.getactionstrength("right") - Input.getactionstrength("left"))*speed
if sign(move.x) == 0:
$Sprite.flip_h = lastdir == -1
elif sign(move.x) == -1:
lastdir = -1
$Sprite.flip_h = true
lastdir = 1
$Sprite.flip_h = false
if move.y < 0: $Sprite.play("jump")
if move.x != 0: $Sprite.play("run")
else: $Sprite.play("idle")

   if Input.is_action_pressed("up") and is_on_floor():
    move.y = jump_speed
move_and_slide(move, Vector2.UP)
in Engine by (21 points)

1 Answer

+1 vote
Best answer


func _physics_process(delta):
    move.y += gravity


func _physics_process(delta):
    if is_on_floor():
        move.y = 0
        move.y += gravity

should work. No need to accumulate gravity if your character is on the floor.

by (3,665 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.