Godot Version
4.2.1
Question
Hello everyone, I’m working on an educational game about freight stations and I’m stuck on the physics of my freight cars. I use Area2D with CollisionShape2D in front and rear of the freight cars.
Because there move freight cars without locomotives in a freight station there could be a collision in front or rear with different speeds.
In the picture you can see 4 freight cars. The car with speed -80 will hit the car with speed 0 first and it works. Around the same time the car with speed 150 will hit the car with speed 100 which also works and both will hit the car with speed 0 but after that it gets weird.
Maybe someone has a better solution to the whole problem or at least a better idea when I can set the Collision_Object = null again.
if Collision_Object_front != null:
if absf(Collision_Object_front.get_speed()) > absf(speed):
speed = Collision_Object_front.get_speed()
else:
Collision_Object_front.set_speed(speed - 20)
Collision_Object_front = null
if Collision_Object_rear != null:
if absf(Collision_Object_rear.get_speed()) > absf(speed):
speed = Collision_Object_rear.get_speed()
else:
Collision_Object_rear.set_speed(speed - 20)
Collision_Object_rear = null