supertuxkart / stk-code

The code base of supertuxkart
Other
4.4k stars 1.03k forks source link

Collisions between cylindrical soccer ball and static rotating objects #4939

Open kimden opened 7 months ago

kimden commented 7 months ago

Description

When the map has a static object with rotation animation, the karts collide with it just fine, while the soccer ball / puck behaves unexpectedly (e.g. it can either pass through the object, or get stuck in it, or bounce back while the karts will just hit it and won't move further as expected).

It does not happen if the animation is just movement, in this case everything is fine. It happens for sure when the ball is cylindrical (puck). I recall someone testing the spherical ball being fine, but I don't really remember the circumstances.

Steps to reproduce

  1. Take or create a soccer map with a certain object having a rotation animation, and preferably with a cylindrical ball.
  2. Try to hit it with a kart and with a soccer ball.

An existing example is the center hall of Emerald Arena in addons.

Configuration

STK release version: Occurred in 1.2, 1.3, 1.4 (not sure about earlier versions)

STK Source (PPA, distribution package, official binary, etc.): git

kimden commented 2 months ago

I checked out physics/physics.cpp, more specifically solveGroup() and update() functions.

In solveGroup(), apparently a collision between UP_PHYSICAL_OBJECT and UP_PHYSICAL_OBJECT does not result in a push_back to m_all_collisions, just as collisions between UP_ANIMATION and almost all other types except UP_KART, and between UP_TRACK and UP_TRACK (which I guess cannot happen anyway).

When I changed it to create a new item in m_all_collisions when both objects are UP_PHYSICAL_OBJECT, and to not handle it in any way in update(), the ball started bouncing away (sometimes with strange collisions, but it's probably solvable by putting thicker walls in a rotated object.

I'm not sure why the types of collisions above are currently not handled. I guess different "non-playable" animated objects indeed shouldn't collide physically, but that shouldn't apply to ball/puck. Probably just adding a physical-physical collision with the condition that one of them is a soccer ball would be enough. I'm not really sure though. In any case, I might be not aware of other places where something needs to be fixed.

On a related note, it seems like plungers are going through such rotating objects, and bowling balls don't bounce off them but disappear. Probably it's happening for the same reasons.