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

Why doesn't my bullet fly straight? *Un-answered*

Asked by
Relatch 550 Moderation Voter
10 years ago

When I click, the bullet doesn't go straight. Instead, it comes out different ways. I don't know why it does this. Help?

01local tool = script.Parent
02local reloading = script.Parent.Reloading
03local autofire = false
04 
05function fireBullet(d)
06    local bullet = Instance.new("Part")
07    bullet.FormFactor = "Custom"
08    bullet.Size = Vector3.new(1.5, 0.35, 0.35)
09    bullet.BrickColor = BrickColor.new("White")
10    bullet.Position = tool.Handle.Position + (d * 5)
11    bullet.Velocity = d * 125
12 
13    local s = script.RemoveBullet:Clone()
14    s.Disabled = false
15    s.Parent = bullet
View all 77 lines...

3 answers

Log in to vote
0
Answered by 10 years ago

Try changing your force to this.

1force.force = Vector3.new(0,100,0) -- 100 is perfect. its a mostly straight shot

If that doesn't work then put it like this

1force.force = Vector3.new(100,0,0)

Or this

1force.force = Vector3.new(0,0,100)
Ad
Log in to vote
0
Answered by 10 years ago

The mass of every object in ROBLOX is measured by it's volume. In order to get an object's volume, you have to multiple the Width by the Length by the Height.

1local BrickMass = Brick.Size.X * Brick.Size.Y * Brick.Size.Z

This is for any brick.

Now that number alone only gives you mass of the object. Now we have to find out what the exact weight of that object is.

In physics, you learn that the weight of an object is simply M * g, which is the Mass of the object multiplied by the gravitational acceleration in that environment. On Earth, the gravitation acceleration is 9.81 m/s^2. This means that an object in free fall will accelerate at 9.81 m/s^2 downward. The gravitational acceleration in ROBLOX, however, is 196.2 studs/second^2. So to get the weight of the object, take the mass of the object and multiply it by the ROBLOX gravitational acceleration.

1local BrickWeight = BrickMass * 196.2

Now that you have the weight of the brick, you need to put that in the force. Like this:

1force.force = Vector3.new(0, BrickWeight, 0)

And there you go! That'll keep your bullet in a straight line path all the time!

FULL FUNCTION:

01function fireBullet(d)
02    local bullet = Instance.new("Part")
03    bullet.FormFactor = "Custom"
04    bullet.Size = Vector3.new(1.5, 0.35, 0.35)
05    bullet.BrickColor = BrickColor.new("White")
06    bullet.Position = tool.Handle.Position + (d * 5)
07    bullet.Velocity = d * 125
08 
09    local s = script.RemoveBullet:Clone()
10    s.Disabled = false
11    s.Parent = bullet
12 
13    local BulletWeight = Bullet.Size.X * Bullet.Size.Y * Bullet.Size.Z * 196.2 --This gets the force required to keep the bullet hovering
14    local force = Instance.new("BodyForce")
15    force.force = Vector3.new(0, BulletWeight, 0)
16    force.Parent = bullet
17 
18    bullet.Parent = game.Workspace
19end
0
uh.... ok?? thanks mr. scientist. Relatch 550 — 10y
0
Wait, this still doesn't work... Relatch 550 — 10y
0
Nope. Relatch 550 — 10y
Log in to vote
0
Answered by 10 years ago

Look, Do like this:

01function fireBullet(d)
02 
03    local bullet = Instance.new("Part")
04 
05    bullet.FormFactor = "Custom"
06 
07    bullet.Size = Vector3.new(1.5, 0.35, 0.35)
08 
09    bullet.BrickColor = BrickColor.new("White")
10 
11    bullet.CFrame = CFrame.new(script.Parent.Handle.Position,d)
12 
13    bulletForce = Instance.new("BodyVelocity", bullet)
14 
15    bulletForce.maxForce = Vector3.new(math.huge,math.huge,math.huge)
View all 38 lines...

That'd fix the bullet flying in all directions possible error thing. Aight?

Answer this question