The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I'm making a 2d left-to-right style game (In the same vain as games like hollow night, but with a very different story and looks) and I have the following code inside the func get_input(). I have other code in their (more inputs) so if that is necessary please let me know. This code doesn't work. Pressing up appears to do nothing, although "Worked" is printed.

if Input.is_action_just_pressed("up"):
           velocity.y -= 20000
       print("Worked")

This is also in the script.

func _physics_process(delta):
    get_input()
    velocity.y += 100
    velocity = move_and_slide(velocity)
Godot version v3.3.2.stable.official
in Engine by (12 points)

Have you tried using is_action_pressed()?

2 Answers

0 votes

Hi there!
typically when you are making input you don't put them in an Input func but just slap them in _physics_process so the way I would do it would to
(in _physics_process)

   gravity += 30
   if Input.is_action_just_pressed("up"):   
      direction.y = -700
   direction.y = gravity

direction = move_and_slide(direction, Vector2.UP)

hope this help!
if it doesn't work feel free to respond to the comment with questions!

by (107 points)
0 votes

I havent worked with platformers for a while, and I dont know the rest of your code, so take it with a grain of salt, but I think I know what is your problem.

Every frame your velocity.y value goes up by 100, and never resets, so in very little time it would have a value way above the 20000. So by the time you try to substract that amount the value remains positive, and the player dosnt jump. You can see if this is the case by doing a print(velocity.y) in the procces(). A quick fix would be to do velocity.y = 20000 intead of velocity.y += 20000, becasue this way you dont care what value velocity.y had before. There are other ways, like having gravity not working when on floor and what not, but this would do.

by (450 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 Frequently asked questions and 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 [email protected] with your username.