Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

Why does this shooting script have a bit offset from the goal`?

Asked by 6 days ago
Edited 6 days ago
local part = script.Parent
wait(2)
while wait(1) do
    local Bullet = Instance.new("Part", workspace)
    Bullet.Size = Vector3.new(1,1,1)
    local BV = Instance.new("BodyVelocity", Bullet)
    BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    BV.Velocity = (workspace.BadAdmins.HumanoidRootPart.Position - script.Parent.Position).Unit*50 
end

My bullet has a bit of offset and is not hitting me, it is shooting right beside my character. What is the problem?

1 answer

Log in to vote
1
Answered by
gskw 450 Moderation Voter
6 days ago

It appears that you aren't setting the bullet's position where it should go. I assume script.Parent is a gun here. Thus you would want your bullet to start out at the position of your gun, but with this script the bullet actually starts out at the origin (0, 0, 0). After that, the bullet's velocity is calculated using a statement that seems to assume that the bullet starts out inside script.Parent; it creates a vector from the gun to BadAdmins' HumanoidRootPart. All in all, you want to assign the position to an appropriate value:

local part = script.Parent
wait(2)
while wait(1) do
    local Bullet = Instance.new("Part", workspace)
    Bullet.Size = Vector3.new(1,1,1)
    Bullet.Position = part.Position -- Line added here
    local BV = Instance.new("BodyVelocity", Bullet)
    BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    BV.Velocity = (workspace.BadAdmins.HumanoidRootPart.Position - script.Parent.Position).Unit*50 
end
Ad

Answer this question