system
October 11, 2019, 10:05pm
1
Attention
Topic was automatically imported from the old Question2Answer platform.
Asked By
David_sun
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 = move_and_slide(velocity, Vector2.UP, true)
system
October 12, 2019, 10:45am
2
Reply From:
Notorious2016
For move_and_slide() function, do not pass as first parameter a velocity with delta.
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.
David_sun | 2019-10-13 21:00
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.
David_sun | 2019-10-13 21:01
system
October 12, 2019, 11:42am
3
Reply From:
Adam_S
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.
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.
David_sun | 2019-10-13 20:58