-2

My original plan didn't work. pls help

I had a while loop which updates the velocity(the more it falls the more the velocity is) of the ball when is not in floor and jump half the velocity of the fall velocity. But my project is stuck on the laoding screen.

Aaron
  • 1

1 Answers1

0

I had a while loop which updates the velocity

When does the loop end? There is your problem.


Godot - like many game engines and frameworks - has a game loop※, that will call into your code.

In particular it will call into your _process every graphics frame and into your _physics_process every physics frame. See Idle and Physics Processing.

Thus, instead of making your own loop - and preventing Godot's loop from progressing - you should make the updates corresponding to each graphics or physics frame in _process or _physics_process respectively. That way, you can have a process happen across multiple frames.

I'll also want to mention that Godot provides timers, has animation solutions, and that you could use a second thread if you really need to.

For an explanation of what to do in _process vs _physics_process see Godot: _process() vs _physics_process(): I need a valuable example.

※: A game loop is a game development concept. It is the equivalent of an event loop for UI applications. Do not confuse it with a game play loop, which is a game design concept.


Furthermore, Godot has its own physics engine, that can do physics simulations for you. Including, but not limited to a ball bouncing. I went over how to setup physics elsewhere.

See Physics in the official documentation.


Finally, about the problem of the ball. If you are using Godot physics, you can set up how bouncy something is by using a physics material override.

I also want to mention that if you use RigidBody(2D/3D) you can override the method _integrate_forces that would give you more control over the physics state of the body.

If you want to control velocity manually, to have the ball bounce half as much you want to flip the velocity vector, and scale it down by half.

Theraot
  • 31,890
  • 5
  • 57
  • 86
  • Thanks for the answer. I figured it out by my self but i wull still try your way cuz my way is crappy. And again thanks – Aaron Apr 22 '23 at 19:37