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

Bullet shoots only in one direction?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

I made this script which would folloe the cursor and shoot a projectile, however the projectile shoots in only 1 direction, help

Part = game.Workspace.Part
player = game.Players.LocalPlayer
mouse = player:GetMouse()

local prev_mouse_hit 

    mouse.Button1Up:connect(function()
end)

    mouse.Button1Down:connect(function()

            Bullet = Instance.new("Part",workspace)
        game.Debris:AddItem(Bullet,3)
        Bullet.CFrame = CFrame.new(Part.Position,mouse.Origin.p)
        Bullet.Rotation = Vector3.new(Part.Rotation)
        Bullet.CanCollide = false
        Bullet.Transparency = 0.5
        Bullet.BrickColor = BrickColor.new("Bright orange")
        Bullet.Size = Vector3.new(2,2,2)
        Velo = Instance.new("BodyVelocity",Bullet)
        Part.Velocity = Part.CFrame.lookVector*100
        Velo.maxForce = Vector3.new(math.huge,math.huge,math.huge)
        wait(0.25)
    end)
    mouse.Move:connect(function()
        if mouse.Hit.p ~= prev_mouse_hit then
            mouse.TargetFilter = Part
            Part.CFrame = CFrame.new(Part.Position,Vector3.new(mouse.Hit.p.x,1,mouse.Hit.p.z))
            prev_mouse_hit = mouse.Hit.p
    end
end)

1 answer

Log in to vote
2
Answered by 8 years ago

Change:-

Part.Velocity = Part.CFrame.lookVector*100

to this as you need to apply the vector3 to the velocity not the part:-

Velo.Velocity = Part.CFrame.lookVector*100

This will make the bullet shoot the direction that the part is facing.

Ad

Answer this question