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

how to use lookVector when Raycasting?

Asked by 7 years ago
Edited 7 years ago

I have trouble with this, because i am making an Enemy AI, that will shoot projectiles the way i plan to do this is by making a fake mouse, for the AI so i thought Raycasting will work, though it does not seem to as it will only shoot in one direction, or ofcourse if you guys have any better way to do this without raycasting that will be nice, but here is the script

gundb = false
attack = false
chr = script.Parent
guncool = 3
gundur = 0.4
gundamage = 10

local GUN_RANGE = 1000
local torso = chr.Torso
local fmousegun = Ray.new(torso.Position, torso.CFrame.lookVector * GUN_RANGE)

lookAt = (fmousegun.Direction - chr.HumanoidRootPart.CFrame.lookVector).unit    


gunshot = function()
    if gundb == false then
        gundb = true
        attack = true

        chr.EnemyHumanoid.WalkSpeed = 0
        chr.EnemyHumanoid.JumpPower = 0


local rayend, endPoint = workspace:FindPartOnRay(fmousegun) 
    print(rayend)

    local arrow = game.ReplicatedStorage.Enemys.Act1.TroubleMakers.Bullet:clone()
    arrow.BodyVelocity.Velocity = lookAt*(100*1)
    arrow.Damage.Disabled = false   
    arrow.Parent = workspace
    arrow.CFrame = CFrame.new(lookAt * 5)
    arrow.BodyGyro.CFrame = CFrame.new(arrow.CFrame.p,fmousegun.Direction)
    game.Debris:AddItem(arrow,5)        
wait(gundur)    
attack = false  
        chr.EnemyHumanoid.WalkSpeed = 16
        chr.EnemyHumanoid.JumpPower = 50    
wait(guncool)

gundb = false



    end
end





while true do
    wait(2)
    fmousegun = Ray.new(torso.Position, torso.CFrame.lookVector * GUN_RANGE)
    local attacks = 1

    if attacks == 1 and attack == false then
        print("shot")
        gunshot()
    end
end
0
Can you fix your code block else ppl will not take the time to read your question. User#5423 17 — 7y
0
there, sorry about that danielsury06 18 — 7y

Answer this question