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

Why doesn't my bullet fly straight?

Asked by
Relatch 550 Moderation Voter
9 years ago

When I click, the bullet comes out all kinds of different ways. I don't know why it does this, but it does. I just want it to fly straight forward.

function fireBullet(d)
    local bullet = Instance.new("Part")
    bullet.FormFactor = "Custom"
    bullet.Size = Vector3.new(1.5, 0.35, 0.35)
    bullet.BrickColor = BrickColor.new("White")
    bullet.Position = tool.Handle.Position + (d * 5)
    bullet.Velocity = d * 125

    local s = script.RemoveBullet:Clone()
    s.Disabled = false
    s.Parent = bullet

    local force = Instance.new("BodyForce")
    force.force = Vector3.new(0, 25, 0)
    force.Parent = bullet

    bullet.Parent = game.Workspace
end

3 answers

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Neither of these answers are correct.

The direction it flies all depends on what you give the parameter d when you call the function. Since we don't have the code where the function is called, we cannot tell for sure what the problem is.

When I made guns, I usually correctly CFrame the bullet first,

--Point towards mouse
bullet.CFrame = CFrame.new(tool.Handle.CFrame.p, mouse.Hit.p)
--Point forwards from the handle
bullet.CFrame = CFrame.new(tool.Handle.CFrame.p)

then I make it fly forwards according to its lookVector. (where the part is "looking"; its Front Face.)

bullet.Velocity = bullet.CFrame.lookVector * 125

Since I do not know what d ends up standing for, I do not know specifically what you're doing wrong. However, I can tell you for sure that speed and BodyForces will not affect how straight the bullet flies.

Ad
Log in to vote
1
Answered by 9 years ago
bullet.Velocity = d * 125

should b like

bullet.Velocity = d * 400

the more you add to the last number, the faster it goes:)

1
What does speed have to do with it flying forward? Relatch 550 — 9y
1
Nevermind, worked. Thanks! Relatch 550 — 9y
0
its k :) i remeber u from my game ConnorVIII 448 — 9y
1
lol, hi Relatch 550 — 9y
View all comments (2 more)
1
Now it makes this loud "OOF" sound when a player is shot and killed. Relatch 550 — 9y
0
Try and change the numbers around to see if it is the bullet that causes the "OOF" or the environment. ConnorVIII 448 — 9y
Log in to vote
0
Answered by 9 years ago

You need to make the Force (0,100,0) That makes a perfectly stright shot.

So like this

function fireBullet(d)
    local bullet = Instance.new("Part")
    bullet.FormFactor = "Custom"
    bullet.Size = Vector3.new(1.5, 0.35, 0.35)
    bullet.BrickColor = BrickColor.new("White")
    bullet.Position = tool.Handle.Position + (d * 5)
    bullet.Velocity = d * 125

    local s = script.RemoveBullet:Clone()
    s.Disabled = false
    s.Parent = bullet

    local force = Instance.new("BodyForce")
    force.force = Vector3.new(0, 100, 0) --This makes it perfectly stright
    force.Parent = bullet

    bullet.Parent = game.Workspace
end

0
Now it goes straight upward. Relatch 550 — 9y
0
Try putting it like (100,0,0) Or (0,0,100) See if that works, if it doesn't then I have nothing for you. minikitkat 687 — 9y

Answer this question