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

Projectile is not very accurate? [UNSOLVED]

Asked by
u_g 90
10 years ago

While I was testing a paintball gun, I noticed that the projectile would sometimes not be directly aligned with the mouse, yet, with other guns with basically the same code, the projectile is fine. Can somebody please take a look at the code and see if there is something preventing it from being accurate?

local Torso = script.Parent.Parent.Torso
    local spawnPos = script.Parent.Barrel.Position -- Where to spawn the Bullet
-- more code for bullet
if aiming == false then
    bullet.Velocity = v * 500
    --[[local x, y, z = bullet.Velocity.x, bullet.Velocity.y, bullet.Velocity.z
        x = x + inaccuracyx
        y = y + inaccuracyy
        z = z + inaccuracyz
        bullet.Velocity = Vector3.new(x, y, z)]]--
    end
local bf = Instance.new("BodyForce", bullet)
    bf.force = Vector3.new(0, 100, 0)
local character = script.Parent.Parent
    local humanoid = character.Humanoid
    local targetPos = humanoid.TargetPoint -- Find where the humanoid is targeting
        local lookAt = (targetPos).unit -- Find where the humanoid is targeting
        local ammo = script.Parent.Ammo
        if ammo.Value <= 0 then
            script.Parent.Handle.GunEmptySound:Play()
            enabled.Value = false
            update()
        end
        if canfire == false then
            enabled.Value = false
        return end
        if canfire == true then
        if ammo.Value > 0 then
            ammo.Value = ammo.Value - 1

fire(lookAt)
script.Parent.Handle.FireSound:Play()
update()
wait(0.3)
enabled.Value = false


Answer this question