Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i make this humanoid shoot in the target direction?

Asked by 10 years ago
torso = script.Parent.Torso
maxrange = 70
minrange = 20
target = nil
tor = nil

function findNearestTarget()
    plrs = game.Players:GetChildren()
    for i, plr in ipairs(plrs) do
        if plr.Character ~= nil then
            if plr.Character:findFirstChild("Humanoid") and plr.Character.Humanoid.Health>0 then
                tor = plr.Character.Torso
                if target == nil then
                    if ((torso.Position - tor.Position).magnitude <= maxrange)  then
                        if ((torso.Position - tor.Position).magnitude >= minrange) then
                            target = plr.Character
                        else
                            target = nil
                            script.Parent.Zombie:MoveTo(script.Parent.Head.Position, script.Parent.Head)
                        end     
                    else
                        target = nil
                        script.Parent.Zombie:MoveTo(script.Parent.Head.Position, script.Parent.Head)
                    end
                end
            end
        end
    end
end

head = script.Parent:WaitForChild("Head")

function Shoot ()
    local ball = Instance.new("Part")
    ball.Name = "Ball"
    ball.BrickColor = BrickColor.new("White")
    ball.Shape = "Ball"
    ball.Size = Vector3.new(1,1,1)
    ball.CanCollide = false
    ball.CFrame = head.CFrame
    ball.Velocity = tor.CFrame*20
    ball.Parent = game.Workspace
end

while true do
    wait(.1)
    findNearestTarget()
    if target ~= nil then
        wait(2)
        Shoot()
        print ("Shooted")
    end
end

So, what this is supposed to do, is that when this humanoid has a target he shoots on its direction. But he shoots downward and not on the targets direction. Help?

1 answer

Log in to vote
-1
Answered by
KAAK82 16
10 years ago

the FrontSurface of the part that the ball ball comes out off has to Face ere he is Facing...

0
hes shooting downwards DragonOfWar900 397 — 10y
0
dude -_- u dont kno nothing! :P I made my Gun like a fe Days ago, I made the same Mistake :P I learned from my Mistake... the Front Surface needs to be facing forards, cos if there's no focus part, then the only choice for the system is the front surface :P try it, believe me... u dont just Thumbs Don cos u think it's rong :P try it first then Judge... KAAK82 16 — 10y
Ad

Answer this question