Sphere falls through moving diagonal surface

Hi, I really need help with this.
I’m making a 3D sidescrolling game where you have to roll a ball, and the rest is done by physics. You have to jump ‘canyons’ and overcome other obstacles.

Up till now everything was going alright, but now I made a canyon with a floating platform that goes back and forth from left to right. The player first has to jump onto the platform and then wait till it goes across again, so he can jump to the other side.

I used two (diagonal) ramps which I made in 3ds max and gave a Mesh Collider. The player has a Sphere Collider.
But the ball just ‘falls’ through the ramps as soon as the platform starts moving:

  • As long as the platform is idle, nothing’s wrong.

  • If I use only horizontal and vertical Cubes, the ball doesn’t go through.

  • If I cover the ramps with (diagonal) Unity Cubes, the ball WILL still go through.

It seems that the diagonal factor messes everything up. But this is the core of my game, if I can’t get this to work, the whole game is worthless.


I read all the other problems concerning GameObjects going through things at high speed or when they’re really small, but none of those apply to my problem.
I tried the DontGoThroughThings-script, but that only checks the direction the ball is going in, and that’s not the direction in which the ball is hitting the ramps.
Then I wanted to create 8 raycasts (at 0, 45, 90, 135, 180, 225, 270 and 315 degrees) from the position of the ball, but I think then the ball would never move again because the x- and y-movements will always be completely restricted if one ray hits anything.

What I need is to restrict the movement in only the angle at which it hits the ground (or ceiling or wall or any object), but to my knowledge this isn’t possible.


The whole project can be [65830-ballgame.zip|65830]

Player, Camera, and Floater have a script.
The Floater is inside Track > TrackCanyon2 (see the image)

Game controls:

  • Roll ball: spacebar
  • Move camera: arrows/WASD
  • Reset camera: V

I’m at a loss here! Any help would be greatly appreciated.

they way you are setting the floating platform’s position does not agree with the physics. Don’t use transform.position to move the platform. Put a rigidbody on it and use rigidbody.velocity to move the floater. It will respect the ball physics.

When moving the platform with transform.position, the ball collider will clip the mesh collider of the platform causing it to fall trough the collider. There are two possible ways to solve this.

  1. Parent the platform to the ball on collision so the transform.position movement will be inherited. Unparent the platform when the ball leaves collision.

  2. Attach a rigid body to the platform and move the platform using physics.