0 votes

Hello.
does anyone know why constant gravity doesn't work?

extends KinematicBody2D

const GRAVITY = 800
onready var velocity:Vector2 =Vector2.ZERO

func ready():
pass
func _physics
process(delta):
velocity.y += GRAVITY * delta
velocity = moveandslide(velocity, Vector2.UP, true)

asked Oct 11, 2019 in Engine by David_sun (24 points)

2 Answers

0 votes

For moveandslide() function, do not pass as first parameter a velocity with delta.

answered Oct 12, 2019 by Notorious2016 (24 points)

gracias por la respuesta

El codigo estava correcto.
El problema estaba en un archivo PNG corrupto...
Tuve que rehacer toda la escena pero funcionó.

Muchas gracias de nuevo.

Thanks for the reply

The code would be correct.
The problem was in a corrupt PNG file ...
I had to redo the whole scene but it worked.

Thank you very much again.

0 votes

Seems like your _physics_process doesn't run at all, cause your player should fall.
You probably wrote something wrong, make sure your _physics_process looks like this:

func _physics_process(delta):
    velocity.y += GRAVITY
    velocity = move_and_slide(velocity, Vector2.UP, true)

Do not multiply the velocity by delta, since the move_and_slide function already does, as you can read here.

You should use the formatting feature when posting code here, so it's easier to help you.

answered Oct 12, 2019 by Adam_S (981 points)
edited Oct 12, 2019 by Adam_S

Thanks for the reply

The code would be correct.
The problem was in a corrupt PNG file ...
I had to redo the whole scene but it worked.

Thank you very much again.

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.