Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | void11 |
Hi All,
I Am fairly new to game development and coding, so apologies if this is a newbie question/problem
How to add function in Godot that will move “up” constant and smoothly while key is held and then when key released for gravity to work
The idea is to have movement for the “player” similar to, if a balloon was filled with air it would rise and then if released it would fall, the code below is what i have tried , it works kind of , although it is still more of a jump action as i need to keep pressing, rather than holding for a smooth elevation. I have also tried “is_action_pressed” also but as I hold it freezes the sprite until I release then it performs the jump
extends KinematicBody2D
const GRAVITY = 10
var motion = Vector2(80,0)
func _physics_process(delta):
apply_gravity()
func apply_gravity():
if Input.is_action_just_pressed(“move up”):
motion.y = -500
else:
motion.y += GRAVITY
move_and_slide(motion)