You can use the code in a Follow brick to move around non-humanoids.
Here it is modified to Move an insect up and down walls (Half finished script, but it works). Steal from it. It is in HumanoidRootPart
function DrawRay(origin, direction)
is new. might have errors.
wait(1)
bin = script.Parent
local Players = game:GetService(“Players”)
local humanoid = bin.Parent.Humanoid
local HipHeight = .9 – Not used yet: An absolute, relative to what the spider is standing on…
local HIPHEIGHT = .9 – How far off the ground; HumanoidRootPart will be:
–Mike, maybe I should read this from the Humanoid…?
– But you need to set this more precisley, anyway…
– At the moment, “Spider002”; renamed “SpiderTorso”,
– is lower than the actual feet of the Spider
– so this number is bogus… A bit too high.
– To set; No colliable part should actually be touching the floor
– (I’m using a Part called SpiderTorso to measure the width of the
– Spider and Ray’s Height, will shoot from the bottom of this Part)
–local SpiderTorso = bin.Parent.InsectTorso
–local YOffset = SpiderTorso.Size.y/2
–local XOffset = SpiderTorso.Size.x/2 – Width
–local ZOffset = SpiderTorso.Size.z/2
local TORQUE = 2 – Turning Speed; multiplier
local RootPart = bin.Parent:WaitForChild(“HumanoidRootPart”) – sAME AS BIN ACTUALY…
– Turn into loose body:
humanoid:ChangeState(Enum.HumanoidStateType.Physics)
local Gyro = bin:WaitForChild(“BodyGyro”)
Gyro.cframe = bin.CFrame
Gyro.maxTorque = Vector3.new(10000,10000,10000) * TORQUE
local BodyPos = bin:WaitForChild(“BodyPosition”)
BodyPos.Position = bin.Position
BodyPos.maxForce = Vector3.new(10000,10000,10000) * bin.Speed.Value
local State = humanoid:findFirstChild(“State”) – Spider State
if not State then
State = Instance.new(“StringValue”, humanoid)
State.Name = “State”
end
local Logic = 0 --How far from an orbit are we?
function DrawRay(origin, direction) – origin is a point. Direction is a vector3; it’s magnitude = length
local hitPart
local Position = origin + direction – Destination position, unless hit a part
local Normal
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {bin.Parent} -- whatever model this is in...
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist -- don't hit any parts of us
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
if raycastResult then
hitPart = raycastResult.Instance
Position = raycastResult.Position
Normal = raycastResult.Normal
end
if true then --Graphics for debugging
local RayPart = Instance.new("Part", bin.Parent)
if hitPart then -- Black if hit something
if true then -- You can check which call this cast is for and change the color
RayPart.BrickColor = BrickColor.new("Black") --Set its color.
else
RayPart.BrickColor = BrickColor.new("Bright red") --Set its color.
end
else -- White color if no hit
if true then
RayPart.BrickColor = BrickColor.new("White") --Set its color.
else
RayPart.BrickColor = BrickColor.new("Olive") --Set its color.
end
end
RayPart.Transparency = 0.3 --Set its transparency.
RayPart.Anchored = true --Set whether it will fall or not.
RayPart.CanCollide = false --Set whether people can walk though it or not.
RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
local Distance = (Position-origin).magnitude --Find the distance between the hit and the torso.
local PercentLeft = 3*(1-Distance/(direction).magnitude)+0.3 -- What part of directioon did we not make X 3
RayPart.Size = Vector3.new(.4, PercentLeft, Distance) --Set its size to the distance.
RayPart.CFrame = CFrame.new(Position, origin) * CFrame.new(0,0,-Distance/2) --Move it halfway.
game.Debris:AddItem(RayPart,5) --Add it to the debris.
end -- Graphics
return hitPart, Position, Normal
end
function move(target) – Aim – At a Position
Gyro.cframe = CFrame.new(bin.Position, target)
end
function moveTo(target)
BodyPos.Position = target
end
function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 100
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == “Model”) and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild(“Head”)
– temp = temp2:findFirstChild(“HumanoidRootPart”)
human = temp2:findFirstChild(“Humanoid”)
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
local players = Players:GetPlayers()
for i, player in pairs (players) do
if player.Character then
if player.Character:FindFirstChild(“HumanoidRootPart”) then
–check for magnitude here
end
end
end
function GetNormal(N) – Square-up to a Normal
move(bin.Position - N)
wait(.1)
end
local UP = Vector3.new(0,6,0)
local DOWN = Vector3.new(0,-6,0)
function ComeBackToLevel(Logic) – Climb Obsticals until reaching a flat level state…
local Facing = bin.CFrame – old position
local Looking = Facing.LookVector
if Logic == 1 then
State.Value = "ClimbingUp"
local dir = (Facing + UP + Looking).Position
–Aim
move(dir) – Face up in the dir we r facing
–turn up
wait(.1)
– start moving up
moveTo(dir)
wait(.1)
–keep moving up
repeat
–print(bin.position.y)
dir = (bin.position + bin.CFrame.LookVector * 6) – Spider is hopefully looking up
moveTo(dir)
wait(.2)
if not DrawRay(bin.Position, bin.CFrame.UpVector * -5) then -- Check if we are still on a wall
Logic = 0
end
until Logic ~= 1
end -- Logic up?
–Climb down
if Logic == -1 then
State.Value = “ClimbingDown”
local dir = (Facing + DOWN + Looking).Position
–Aim
move(dir) – Face down in the dir we r facing
–turn DOWN
wait(.1)
– start moving DOWN
moveTo(dir)
wait(.1)
--keep moving down
repeat
--print(bin.position.y)
dir = (bin.position + bin.CFrame.LookVector * 9) -- Spider is hopefully looking down
moveTo(dir)
wait(.2)
if DrawRay(bin.Position, bin.CFrame.LookVector * 5) then -- Check if a floor is ahead
Logic = 0
end -- floor?
print(“Logic”, Logic)
until Logic ~= -1
end -- Logic down?
– Reset
Gyro.cframe = Facing – reset
wait(.1)
end – Climb until level again
– Main
while true do
local torso = findNearestTorso(bin.Position)
local hit = nil – What Part ray hit
local RayPos – Position Where it hit part
–Player?
if torso~=nil then
local dir = (bin.CFrame.LookVector) * 5 – Ray to check for wall in front
– Wall?
hit, RayPos, Normal = DrawRay(bin.Position, dir)
if hit then
GetNormal(Normal) – Line up perpendicular to wall
Logic = 1
ComeBackToLevel(Logic)
elseif not DrawRay(bin.Position, bin.CFrame.UpVector * -5) then
Logic = -1
ComeBackToLevel(Logic)
end
–Aim
move(Vector3.new(torso.Position.x, bin.position.y, torso.Position.z)) – Toward Player but at spider’s height
–floor?
dir = (bin.CFrame.UpVector) * -199 – Ray to check for hip height
hit, RayPos = DrawRay(bin.Position, dir)
dir = (bin.CFrame + bin.CFrame.LookVector * 9).Position
if hit then
dir = Vector3.new(dir.x, RayPos.y + HIPHEIGHT, dir.z) -- direction we are aiming + hipheight
end
–Move toward aim
moveTo(dir)
State.Value = “Running”
else – No Player?
State.Value = “NoPlayer”
BodyPos.Position = bin.Position
end
-- Go!
wait(.2)
end