Am I calculate acceleration right? (I receive diffirent outcomes from 1/10 and 1/60 framerates)

Hello guys. I’m trying to make water droplet physics simulation. With raycasting and CFrames. But, sometimes droplet can just pass trough anything. So, after investigation, I found that on smaller framerate, droplet will noclip much, much, MUCH rarer. And this lead me to ask question: am I doing math right?
Code:

local Gravity = 9.8
...
--loop code here, to calculate acceleration and collisions, main problem is acceleration from gravity.
local VelocityGrav = Velocity - Vector3.new(0, Gravity * CurDelay, 0) 
local Offset = VelocityGrav.Unit / 20
local RayStart = -Offset + Start
local RayDirection = VelocityGrav + Offset
local Result = workspace:Raycast(RayStart, RayDirection, SurfaceParams)
local RaycastDistanceTarget = VelocityGrav.Magnitude * CurDelay
local ResultSucceed = Result and Result.Distance <= RaycastDistanceTarget and 2 or Result and 1 or 0

--CurDelay = framerate, 1/10, 1/60. Any.

I’ll appreciate any help.

1 Like

As far as I can tell, yes the math is fine.
The issue is the raylength doesn’t adjust accordingly.

The parts new position is calculated each step and a ray is cast at a fixed length. But this means if there is a smaller time between steps the raycast will be more likely detect the floor. Longer steps will give more chance the new position places the part too far from the floor to detect with the raycast, but close enough to clip on the next step.

The solution would be to adjust the ray length according to the time interval between steps.

2 Likes

This’s really was reason why raycasts won’t detect surface. In most cases. But sadly, still not in all:

local RDT = (VelocityGrav.Magnitude + Offset.Magnitude) * CurDelay + 0.05
2 Likes

I’m not sure, it looks like you’ve already done it, but it would need to also account for the extra distance travelled from acceleration. Is the part moved before or after the raycast?

1 Like

Part moved after all raycasts are did.

1 Like