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

How do I change the direction that the bullet shoots in?

Asked by 4 years ago
local Damage = 50
local HeadshotDamage = 100

script.Parent.FireEv.OnServerEvent:Connect(function(Player, Shooter, MousePos)
    script.Parent.FirePart.Fire:Play()
    local Bullet = Instance.new("Part", workspace)
    Bullet.CFrame = script.Parent.FirePart.CFrame
    Bullet.Orientation = Bullet.Orientation + Vector3.new(0, 90, 0)
    Bullet.Size = Vector3.new(0.75, 0.15, 0.15)
    Bullet.BrickColor = BrickColor.new("Bright yellow")
    Bullet.TopSurface = "Smooth"
    Bullet.BottomSurface = "Smooth"
    Bullet.Material = "Neon"
    Bullet.CanCollide = false
    local BVol = Instance.new("BodyVelocity", Bullet)
    BVol.P = 100
    Bvol.Velocity = MousePos
    local I = 0
    while I > 100 do
        Bullet.Touched:Connect(function(Toucher)
            if Toucher.Parent == Shooter then return end
            local Hum = Toucher.Parent.Humanoid
            if not Hum then return end
            if Toucher.Name == "Head" then
                Hum:TakeDamage(HeadshotDamage)
            else
                Hum:TakeDamage(Damage)
            end
        end)
        I = I + 1
        wait()
    end
    Bullet:Destroy()
end)

I'm using BodyVelocity (I know it's bad but it's what I know for now) to move the bullet around. When I try to fire it up, it simply continues pushing forwards instead of moving upwards. It seems to actually change its power depending on where the mouse is. How can I fix this mistake?

1 answer

Log in to vote
1
Answered by 4 years ago

Just replace the BodyVelocity with BodyForce its a bit different but the reason your bullet will only shoot in a straight line is because BodyVelocity moves objects in local space and not with a quaternion

Ad

Answer this question