How to make a part randomly move up hills

So basically, I made this tornado and it works fine and all, but it only moves randomly on the Z and X axis not on the Y, I don’t want it to move Randomly on the Y axis, only enough so that it does not sink into the ground, because my game has a volcano, and when the tornado goes straight into the volcano instead of going up it, it looks weird.

any and all help appreciated.

1 Like

You could probably raycast down from where the tornado is and move it to where the raycast hit. You’ll need to offset the tornado upwards by half it’s Y size, or set the tornado’s pivot to be at the bottom and use :PivotTo(). Something like:

-- After your random X/Z axis movement code
local TornadoRaycastFilter = RaycastParams.new()
TornadoRaycastFilter.FilterType = Enum.RaycastFilterType.Include
TornadoRaycastFilter.FilterDescendantInstances = {workspace.Map} -- Put your map in here
local TornadoRaycastResult = workspace:Raycast(Tornado.Position + Vector3.new(0, 100, 0), Vector3.new(0, -200, 0), TornadoRaycastFilter)

Tornado:PivotTo(CFrame.new(TornadoRaycastResult.Position))
2 Likes

I use body position for my movement, so idk where to put your script

while true do
	script.Parent.Position = Vector3.new(game.Workspace.Storm.Tornado.Position.X+math.random(-300,300),game.Workspace.Storm.Tornado.Position.Y+math.random(0,300),game.Workspace.Storm.Tornado.Position.Z+math.random(-300,300))
	wait()
end

it still should work, just put it underneath the second line (also make sure to set the tornado’s pivot!)

1 Like

Sorry for the late reply, my tornado was buggin out so I had to edit the move script, and now I am getting errors that say ‘FilterDescendantInstances’ is not a valid member of RaycastParams - Server - Movement:8

local Tornado = script.Parent.Parent
local Main = script.Parent
while true do
	Main.CFrame = CFrame.new(Main.Position.X + math.random(-5,5),Main.Position.Y,Main.Position.Z + math.random(-5,5))
	-- After your random X/Z axis movement code
	local TornadoRaycastFilter = RaycastParams.new()
	TornadoRaycastFilter.FilterType = Enum.RaycastFilterType.Include
	TornadoRaycastFilter.FilterDescendantInstances = {workspace.Map} -- Put your map in here
	local TornadoRaycastResult = workspace:Raycast(Tornado.Position + Vector3.new(0, 100, 0), Vector3.new(0, -200, 0), TornadoRaycastFilter)

	Tornado:PivotTo(CFrame.new(TornadoRaycastResult.Position))
	
	wait()
end

Sorry for the late reply, it’s a typo, it’s meant to be FilterDescendantsInstances, not FilterDescendantInstances.

1 Like