So I need help with adding this part of the script to this script:
Script:
for wheelName, originalPosition in pairs(WheelPositions) do
local vehicleCFrame = Chassis.CFrame
local rayOrigin = vehicleCFrame:ToWorldSpace(CFrame.new(originalPosition)).Position
local rayDirection = -vehicleCFrame.UpVector * (suspensionMaxLength + wheelRadius)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local RaycastDistance = (rayOrigin - raycastResult.Position).Magnitude
local SpringLength = math.clamp(RaycastDistance - wheelRadius, 0, suspensionMaxLength)
local StiffnessForce = stiffness * (suspensionMaxLength - SpringLength)
local DamperForce = damper * ((SuspensionLengthMemory[wheelName] - SpringLength) / delta)
local SuspensionForceVector3 = vehicleCFrame.UpVector * (StiffnessForce + DamperForce)
local RotationsOnlyWheelDirectionCFrame = CFrame.lookAt(Vector3.zero, vehicleCFrame.LookVector, vehicleCFrame.UpVector)
if string.sub(wheelName, 1, 1) == "F" then
RotationsOnlyWheelDirectionCFrame *= CFrame.Angles(0, -math.rad(smoothSteer * steerAngle), 0)
end
local LocalVelocity = RotationsOnlyWheelDirectionCFrame:ToObjectSpace(CFrame.new(Chassis:GetVelocityAtPosition(raycastResult.Position)))
local XForce = vehicleCFrame.RightVector * -LocalVelocity.X * wheelFriction
local ZForce = vehicleCFrame.LookVector * VehicleSeat.ThrottleFloat * torque * (1 - math.min(1, math.abs(LocalVelocity.Z)/maxSpeed))
SuspensionLengthMemory[wheelName] = SpringLength
Chassis:ApplyImpulseAtPosition(SuspensionForceVector3 + XForce + ZForce, raycastResult.Position)
end
end
Add:
local degrees = -10
local range = part.Size.Y/2
RunService.Heartbeat:Connect(function(delta)
for i = 360, -360, degrees do
local Angle = i
local Rotation = CFrame.Angles(math.rad(Angle), 0,0)
local rayAngle = Ray.new(part.CFrame.Position, (part.CFrame * Rotation).LookVector * range)
local raycastResult = workspace:Raycast(part.Position, rayAngle.Direction, raycastParams)
if raycastResult then
end
end
end)
The first script is a one raycast and the second script is a multi-raycast script.
Followed a tutorial from:
Any help appreciated.