0 votes

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 "isactionpressed" 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 physicsprocess(delta):

func applygravity():
if Input.is
actionjustpressed("move up"):
motion.y = -500
motion.y += GRAVITY

Godot version 3.2.3
in Engine by (12 points)

1 Answer

0 votes

Input.is_action_pressed("move up") should work. Maybe try Input.getactionstrength("move up") instead?

When something behaves unexpectedly, the general solution is to add prints to pinpoint where things went weird. You could try a print(motion_y) at the end, as well as a print("Pressed") inside the first case of your if.

by (2,276 points)
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.