Hello everyone. For the past few weeks I’ve been trying to conjure up a decent ball system to use for my first game. I want it to be able to detect all collisions.
Currently I run a basic physics simulation and cast a ray from the ball’s “edge” in the direction of it’s velocity. If a hit is detected, the ball bounces. If the ray distance or velocity magnitude is below a certain threshold, the ball enters a resting state to prevent it from sinking through the ground.
My questions are: Is this even a viable solution (talking about the collisions specifically) and is there a way for me to improve it. The ball still sinks through the ground sometimes, although its very rare and only under certain conditions.
Video:
For those who want a bit more info, this is what I want to achieve (reference):
Cool to see you havent given up it’s looking very nice, I would say the syncing is probably due to floating point numbers and I think the best way of handling the collisions is casting a ray in the direction of velocity like your already doing, because how else would you know in what direction the ball shouldnt bounce off of?
I have tried implementing shapecast with my current code, but I cant get it to work nicely. Maybe I’m doing the math wrong, but it always just sinks into the ground…
Yeah even if I set the position of the ball to where it collided (so ON the ground), it still slowly sinks down because I guess the velocity is faster than the raycast or the floating point numbers get rounded into oblivion. Either way, it works well, but I feel like shapecasting would work better, if only I could implement it properly.
Maybe it’s because the origin raycast position is already submerged into the “ground” part.
Check if you can also use workspace:GetPartBoundsInRadius() if the raycast doesn’t return a value.