Moving a part to the height of the ground

  1. What do you want to achieve? I want to recreate this effect:


    (red part, not the rest)

  2. 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

  3. 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)

Any help is appreciated!

RobloxStudioBeta_MSIxiHKt89
image

local Robot = workspace.Robot

local Ball = Instance.new("Part")
Ball.Shape = "Ball"
Ball.Size = Vector3.new(1, 1, 1)
Ball.CanCollide = false
Ball.Anchored = true
Ball.Color = Color3.fromRGB(255, 0, 0)
Ball.Name = "Ball"
Ball.Parent = workspace

local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Ball}

game:GetService("RunService").Heartbeat:Connect(function()
	local Pos = Robot.Attachment.WorldCFrame
	
	local Origin = Pos.Position
	local Direction = -Pos.UpVector * 10
	
	local Cast = workspace:Raycast(Origin, Direction, Params)
	
	if (Cast) then 
		Ball.Position = Cast.Position
	end
end)
1 Like

This is EXACTLY what I was looking for. Thank you so much!!

he
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 :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)

u can do it like

		Params.FilterType = Enum.RaycastFilterType.Blacklist
		Params.FilterDescendantsInstances = Robot:GetDescendants()

and set Ball.CanQuery to false

this method seemed to work fine for me

1 Like

Thank you this worked for me aswell!

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