What do you want to achieve? I want to recreate this effect:
(red part, not the rest)
What is the issue? I don’t know how to set the height to the height of the current ground + when the part is IN a part the height of the part doesn’t get recognized, maybe because the raycast params are wrong
What solutions have you tried so far? Already calculated the height difference between the Target Point (Attachment) and the nearest part to the ground:
local RunService = game:GetService("RunService")
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {workspace.Robot.Torso}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.IgnoreWater = true
local function raycast()
local Attachment = workspace.Robot.Torso.Arm2
local rayOrgin = Attachment.TargetPoint.WorldCFrame.Position
local rayDirection = -Attachment.TargetPoint.WorldCFrame.UpVector*10 -- ray goes down from the TargetPoint
local raycastResult = workspace:Raycast(rayOrgin, rayDirection, raycastParams)
local oldistanceFromGround = (rayOrgin - raycastResult.Position).Magnitude
local distanceFromGround = 0
if raycastResult then
distanceFromGround = (rayOrgin - raycastResult.Position).Magnitude
if distanceFromGround ~= oldistanceFromGround then
print(distanceFromGround) -- don't know what to do here
end
end
end
RunService.Heartbeat:Connect(function()
raycast()
end)
As you can see here, I have 4 legs which each 3 parts of the spider which I would add into my Ignore List:
local IgnoreList = {v.Ball, Robot.Arm1:GetDescendants(), Robot.Arm2:GetDescendants(), Robot.Arm3:GetDescendants(), Robot.Arm4:GetDescendants()}
local Ball = v.Ball
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {IgnoreList}
this is how it turned out:
Im confused , It seems like the ball jumps between the cast and the attachment itself, maybe it is because of this:
if (Cast) then
Ball.Position = Vector3.new(Cast.Position.X, Cast.Position.Y + 2, Cast.Position.Z)
end
``` ( I added + 2 on the yAxis because the legs follow the ball)