I have this npc that I am making walk. This works fine on a normal character but on this one it falls down, How do I fix this? I have can collide on.
1 Like
Anchor itㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
1 Like
The other blocky ones are not anchored. And when I anchor it, it won’t move.
1 Like
Mind sending the scripts used to control the movement of the droid?
1 Like
I followed a tutorial.
local myHuman = script.Parent:WaitForChild("Humanoid")
local myTorso = script.Parent:WaitForChild("Torso")
local rarm = script.Parent:WaitForChild("Right Arm")
local M4 = script.Parent:WaitForChild("M4")
local grip = M4:WaitForChild("BackGrip")
local barrel = M4:WaitForChild("Barrel")
local equipSound = barrel:WaitForChild("Equip")
local fireSound = barrel:WaitForChild("Fire")
local clone = script.Parent:Clone()
local aim = script.Parent:WaitForChild("Aim")
local aimAnimation = myHuman:LoadAnimation(aim)
aimAnimation.Priority = Enum.AnimationPriority.Action
function checkSight(target)
local ray = Ray.new(myTorso.Position, (target.Position - myTorso.Position).Unit * 40)
local part,position = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
if part then
if part:IsDescendantOf(target.Parent) then
if math.abs(position.y - myTorso.Position.Y) < 1 then
return true
end
end
end
return false
end
function findTarget()
local dist = 100
local target = nil
local potentialTargets = {}
local seeTargets = {}
for i,v in ipairs(workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local torso = v:FindFirstChild("Torso") or v:FindFirstChild("HumanoidRootPart")
if human and torso and v.Name ~= script.Parent.Name then
if (myTorso.Position - torso.Position).magnitude < dist and human.Health > 0 then
table.insert(potentialTargets,torso)
end
end
end
if #potentialTargets > 0 then
for i,v in ipairs(potentialTargets) do
if checkSight(v) then
table.insert(seeTargets,v)
end
end
if #seeTargets > 0 then
for i,v in ipairs(seeTargets) do
if (myTorso.Position - v.Position).magnitude < dist then
target = v
dist = (myTorso.Position - v.Position).magnitude
end
end
else
for i,v in ipairs(potentialTargets) do
if (myTorso.Position - v.Position).magnitude < dist then
target = v
dist = (myTorso.Position - v.Position).magnitude
end
end
end
end
return target
end
function pathToLocation(target)
local path = game:GetService("PathfindingService"):CreatePath()
path:ComputeAsync(myTorso.Position, target.Position)
local waypoints = path:GetWaypoints()
for _,waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
myHuman.Jump = true
end
myHuman:MoveTo(waypoint.Position)
myHuman.MoveToFinished:Wait(2)
if checkSight(target) then
Attack(target)
break
end
end
end
function walkRandom()
local randX = math.random(-100,100)
local randZ = math.random(-100,100)
local goal = myTorso.Position + Vector3.new(randX, 0, randZ)
local path = game:GetService("PathfindingService"):CreatePath()
path:ComputeAsync(myTorso.Position, goal)
local waypoints = path:GetWaypoints()
if path.Status == Enum.PathStatus.Success then
for _,waypoint in ipairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
myHuman.Jump = true
end
myHuman:MoveTo(waypoint.Position)
myHuman.MoveToFinished:Wait(2)
end
else
print("Path failed")
wait(2)
end
end
function Shoot()
local flash = Instance.new("PointLight",barrel)
flash.Brightness = 10
flash.Color = Color3.fromRGB(4, 175, 236)
game:GetService("Debris"):AddItem(flash,0.1)
local bullet = Instance.new("Part",workspace)
bullet.Size = Vector3.new(0.1,0.5,0.1)
bullet.BrickColor = BrickColor.new("Gold")
bullet.Velocity = myTorso.CFrame.lookVector * 400
bullet.CFrame = barrel.CFrame
bullet.CanCollide = false
bullet.Touched:Connect(function(obj)
if not obj:IsDescendantOf(script.Parent) then
local human = obj.Parent:FindFirstChild("Humanoid")
if human then
human:TakeDamage(45)
end
bullet:Destroy()
end
end)
fireSound:Play()
game:GetService("Debris"):AddItem(bullet, 5)
end
function Attack(target)
local tWeld = Instance.new("Weld", script.Parent)
tWeld.Part0 = grip
tWeld.Part1 = rarm
tWeld.C0 = CFrame.new(0.5,-0.5,0.9) * CFrame.Angles(math.rad(-90),math.rad(65),math.rad(-115))
equipSound:Play()
repeat
aimAnimation:Play()
local forwardVector = (target.Position - myTorso.Position).Unit
local upVector = Vector3.new(0,1,0)
local rightVector = forwardVector:Cross(upVector)
for i = 0, 1, 0.1 do
wait()
myTorso.CFrame = myTorso.CFrame:lerp(CFrame.fromMatrix(myTorso.Position, rightVector, upVector),i)
end
Shoot()
if (myTorso.Position - target.Position).magnitude < 15 then
myHuman.AutoRotate = false
local c = myTorso.CFrame * CFrame.new(0,0,5)
myHuman:MoveTo(c.p)
elseif (myTorso.Position - target.Position).magnitude > 30 then
myHuman.AutoRotate = false
local c = myTorso.CFrame * CFrame.new(0,0,-5)
myHuman:MoveTo(c.p)
end
wait(0.3)
myHuman.AutoRotate = true
until checkSight(target) == false or target == nil or target.Parent.Humanoid.Health < 1
game:GetService("Debris"):AddItem(tWeld,0)
equipSound:Play()
end
function main()
local target = findTarget()
if target then
pathToLocation(target)
else
walkRandom()
end
end
function Died()
wait(5)
clone.Parent = workspace
game:GetService("Debris"):AddItem(script.Parent,0)
end
myHuman.Died:Connect(Died)
while wait(1) do
main()
end
1 Like
Looking at it from a physics perspective, you could do the following:
- Set the mass of all the droid body parts equal to 0 and set their CanCollide to false
- Use the normal R6 player model and weld the arm parts to the arms, leg parts to the legs, etc.
- Set the transparency of the R6 player model equal to 0
If necessary, also rename the preexisting droid parts so the script doesn’t get them confused
1 Like
I only had to do this for the torso and it worked. Thanks!
1 Like
No problem ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
2 Likes