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

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

Asked by 5 years ago
Edited 5 years 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 1046 Moderation Voter
5 years 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