Hello,
i am building a billiard game, and i currently have a raycast system in place… it is a little off but through some tuning i think i can make it better… ive been thinking about a method to get ultra accurate raycasting, which includes the raycasing of curves and even jumps of the cue ball…
the reason i am posting this is because i want to know if this is possible and if so i would appreciate anyones opinion on how to implement…
here is my logic:
-
at every instant i would like to offscreen somehow render a exact replica of the setup which is on screen… (ball positions, cue position, cue angle, spin and everything neccesary). Updated in real time.
-
i would then at every instant like to move the CueBall forward in time as if a shot was being taken at every frame or so. this is turn would Update the Line Renderer which is shown onScreen and thus give me ultra accurate raycasting/linerendering for line prediction of the cue ball and target ball…
is this possible? if so how?
all and any help is appreciated…
Technically yes… in a physics engine sense. A physics engine can be written to be what is called determinate. And if it is determinate, that means that you can step forward and backwards through the simulation (think like the game Braid).
The way you describe it is effectively the way it’s done.
As for can you do it in Unity? That gets a little more complicated since in Unity there’s not really an easy access point to do it. Just because of how it’s all setup and everything… you CAN technically manual simulate the Physics… ala this method:
But it’s going to simulate ALL physics in the scene.
Basically… in Unity and the way Unity was designed, what you’re asking to do is veeeerrrrrryyyyyy non-trivial.
1 Like
This is easy to work around. You can set the “real” balls to kinematic so that they don’t move, and simulate the fake balls. Or, cache the positions/rotations/etc of the balls and run the simulation on them, then reset afterwards.
2 Likes
thanks allot, this is allot to take in, and to figure out how to implement in the simplest way…
i appreciate the help 
Isn’t there seperate physics scene now?
I didn’t had a chance to use them yet but i thought that what they’re for, simulating ballistic trajectories and what not.
1 Like
that clip with the billiard balls is Exactly what i want to do!!
1 Like
Also, a raycast solution will hardly do in a situation like this, i would try to use a capsulecast as a first measure and a more complex solution to do a bunch of overlapspheres moving it by (velocity * fixedTime) each step, handing what happens after the collisiom though can be very tricky so i’d just go with the seperate scene if it’s an option ( not sure, didn’t use it myself yet)
intresting… i currently have a spherecast actually but you are correct in the way that a spherecast is not enough… as i said in the first post it needs adjustment… i think im gonna go for a combination of the invisible physics scene with the overlapsheres as you said…