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