Hello everybody,
I have a little issue trying to use the Physics2D and RigidBody2D collision system.
I made a 500x500 window with StaticBody2D and RectangleShapes as border. then I put a Rigidbody2D ball with a Sprite2D and CircleShape2D and removed gravity. now I made the ball constantly accelerate. here is the problem, the ball accelerate has it is intended to, but as it gains more and more speed it lasts by fleeing out of the screen.
So how can I prevent the ball of doing this. I've looked the internet to find the correct solution, but I cannot figure out what is the correct answer for godot.
here is the code for the ball:
extends RigidBody2D
var speed = 2000
func ready():
randomize()
setlinearvelocity(Vector2(randrange(-10,10),rand_range(-10,10)))
func getspeed():
var vect = getlinear_velocity()
return (abs(vect.x) + abs(vect.y))
func integrateforces(state):
var vect = getlinearvelocity()
var spd = get_speed()
if spd < speed - 1:
vect *= 1.025
elif spd > speed + 1:
vect *= 0.975
set_linear_velocity(vect)
and there is a screenshot of the project:
screenshot
Thank you for your time.