|Topic was automatically imported from the old Question2Answer platform.
I am a complete beginner and I was trying to learn Godot by making pong.
I did make it but I want to add a feature.
So, I made the ball start at the center, but the problem is that the ball starts moving immediately once I run the program and I don’t want that to happen rather I want to make it so that when I press enter or something else the ball then starts moving.
I tried to achieve this using this
if Input.is_action_pressed: move()
if Input.is_action_just_pressed: move()
but what I encountered was that I had to keep pressing the button to not stop the ball from moving, the ball doesnt start moving with a single click of the button.
My full code:
#movine the ball
var collision = move_and_collide(direction * delta)
#checking for collision
#bouncing the ball
direction = direction.bounce(collision.normal)
I want something like this to happen
this is not the whole code but I assume this is enough
Adding to @Inces answer below, it’s likely that your ball is a RigidBody2D node. If it’s a normal KinematicBody2D, you probably turned on the Motion->Sync to Physics parameter. By default, physics enabled bodies will feel gravitational pull downwards, that’s why your ball is moving before you press anything.
MisterMano | 2021-10-12 14:51
I think I failed to communicate my question properly, sorry for that guys.
- The ball is a static body
- I have no issues with gravity
- The game works how I intend it to work
- The real problem is: The game runs immediately when I run the program, so I want the ball to start moving or the game to start running only after I press a key. Basically what I am trying to say is:
I run the program → you press a key → then the ball starts moving and the game starts
Munchobi | 2021-10-12 15:40
Thank you for your time! I somehow got it working!
Munchobi | 2021-10-13 03:39