Shapecast jittering

so i got this problem with a raycast suspenstion system, it will jittering in place and i dont know how to solve it

im using euler integration instead of a regular spring damped function since it works better at low fps and sudden jumps in length, the only thing changed is the damped part of the equation where you take the last length and the current length subtract and divide by delta time

in the video you can see what the problem is, the shapecast is going crazy on where the hit position should be, the green blocks is where it hits, and the red is the end of the raycast (origin + direction) (blue block you can ignore), somehow the green is moving left and right when it shouldnt really be doing that
the jittering issue doesnt appear when i only use the raycast, but i need the shapecast so the wheel will move with the terrain smoothly instead of jumping when it hits the middle of the wheel

the shapecast is using the wheel as the part, starting at the origin (where the wheel always is) then moving the max length of the spring plus the radius of the wheel down

below is the video:

below is the code:

-- runs on RunService.Hearbeat

local origin = spring.anchorAttachment.WorldPosition

local up = spring.anchorAttachment.WorldCFrame.UpVector
local direction = -up * (spring.maxLength + spring.wheelRadius)

local result = workspace:Shapecast(spring.wheelPart, direction, RAYCAST_PARAMS)
local rayHit = result ~= nil
--print(rayHit)
if rayHit then
	normal = result.Normal
	wheelPosition = result.Position + (up * spring.wheelRadius)
	length = (origin - wheelPosition).Magnitude
else
	debugLinecast(origin, direction, lineResult)
end
debugWheelcast(wheelPosition, spring.wheelPart.Position + direction, result)

i know this can be easily fixed by just caring about the Y axis of the origin and hit position (along the spring direction) but that wouldnt solve that the shapecast is jittering side to side and will mess up at corners

1 Like

The issue stems from the shapecast part being a cylinder. If there is any wobble in the vehicle whatsoever, the collision point will snap from one side to the other, but even in the case where the vehicle is perfectly level, the shapecast collision is technically a line along which there are infinitely many valid intersection points. I’m actually sort of surprised that the function resolves the collision to the center of that line.

The only way to really prevent this jittering is to use a different wheel shape that can only ever collide with level ground at a single point. However, if you project the result to the plane that separates the wheel about its midsection, the result should always be as if the center of the wheel hit the ground.

i figured it out, i just took the current wheel and made its depth very small, then ignored the x and z axis when calculating the length, so the result of the shapecast is mostly in the same spot (with very slight changes since you cant make a part 0 depth), this solved it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.