Gravity (motion.y += not working) for move and slide.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By FilipKench

Movement works properly and all, but gravity that should be caused by the line
I highlithed just doesn’t do anything.

extends KinematicBody2D

var motion = Vector2()

func _physics_process(delta):
motion.y += 10

if Input.is_action_pressed("ui_right"):
	motion.x = 100
elif Input.is_action_pressed("ui_left"):
	motion.x = -100
	motion.x = 0
if Input.is_action_pressed("ui_up"):
	motion.y = -100
elif Input.is_action_pressed("ui_down"):
	motion.y = 100
	motion.y = 0
:bust_in_silhouette: Reply From: timothybrentwood

If you aren’t pressing ui_up or ui_down motion.y will be set to 0 per your else clause, overriding your motion.y += 10 at the top of _physics_process()

Yea pretty simple. Thanks!

FilipKench | 2021-05-07 03:43