Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 05 Jan 2014 02:59 PM |
I just finished a gun and everything works fine, until you move. As soon as you take a step forward, the bullets stop getting propelled forward. My script is kinda lengthy but I'll post it anyways.
tool = script.Parent player = game.Players.LocalPlayer mouse = player:GetMouse() ammo = script.Parent.Ammo storedammo = script.Parent.StoredAmmo maxammo = script.Parent.MaxAmmo enabled = true
function shoot() if ammo.Value > 1 and enabled == true then enable = false firing = true fire() end end
function createBullet() bullet = Instance.new("Part",Workspace) bullet.BrickColor = BrickColor.new("Bright blue") bullet.Reflectance = 0.1 bullet.Transparency = 0.15 bullet.CanCollide = false bullet.Anchored = false bullet.FormFactor = "Custom" bullet.Size = Vector3.new(0.2,0.4,0.2) bullet.BottomSurface = "Smooth" bullet.TopSurface = "Smooth" bullet.CFrame = tool.Barrel.CFrame --bullet.CFrame = CFrame.new(bullet.Position,mouse.Hit.p) tag = Instance.new("StringValue",bullet) tag.Name = "Creator" tag.Value = player.Name newscript = script.Parent.Damage:Clone() newscript.Parent = bullet newscript.Disabled = false mesh = Instance.new("SpecialMesh",bullet) mesh.MeshType = "Head" mesh.Scale = Vector3.new(0.6,1,0.6) light = Instance.new("PointLight",bullet) light.Color = Color3.new(0,115,255) light.Range = 1 light.Shadows = true f = Instance.new("BodyForce",bullet) f.force = Vector3.new(0,bullet:GetMass() * 197, 0) game.Debris:AddItem(bullet,2) end
function burst(v) for i = 1,3 do createBullet() local hum = player.Character:FindFirstChild("Humanoid") local head = player.Character:FindFirstChild("Head") if hum and head then v = (hum.TargetPoint - head.Position).unit end bullet.Velocity = v *100 wait(.1) end end
function fire() repeat burst() ammo.Value = ammo.Value - 3 wait(.5) until firing == false or ammo.Value == 0 end
function stop() firing = false end
tool.Activated:connect(shoot) tool.Deactivated:connect(stop) |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2014 03:21 PM |
Try changing:
bullet.Size = Vector3.new(0.2,0.4,0.2) bullet.BottomSurface = "Smooth" bullet.TopSurface = "Smooth" bullet.CFrame = tool.Barrel.CFrame --bullet.CFrame = CFrame.new(bullet.Position,mouse.Hit.p)
to:
bullet.Size = Vector3.new(0.2,0.4,0.2) bullet.BottomSurface = "Smooth" bullet.TopSurface = "Smooth" bullet.CFrame = tool.Barrel.CFrame+tool.Barrel.CFrame.lookVector*10--lower 10 if your barrel is shorter. --bullet.CFrame = CFrame.new(bullet.Position,mouse.Hit.p)
Alt. of Jetta765214 |
|
|
| Report Abuse |
|
|
Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 05 Jan 2014 03:32 PM |
| Doesn't that just put it in front of the barrel? |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2014 03:34 PM |
yes, i believe the problem is that the bullet is getting stuck in the barrel/touching the character in some way.
Of course i could be wrong, i just did a quick scan through your code.
Alt. of Jetta765214 |
|
|
| Report Abuse |
|
|
Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 05 Jan 2014 03:57 PM |
The bullets should be CanCollide = false. Would it still do that?
|
|
|
| Report Abuse |
|
|
|
| 05 Jan 2014 04:00 PM |
One the gun, make a tip part at the very tip of the mussle thingy.
Then whenever you make a new bullet here's how you CFrame it correctly:
bullet.CFrame = CFrame.new(gun.Hit.CFrame.p + (gun.Hit.CFrame.lookVector * 2), mouse.Hit.p)
|
|
|
| Report Abuse |
|
|
Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 05 Jan 2014 04:00 PM |
| Doesnt work anyways. The bullets still stop after walking |
|
|
| Report Abuse |
|
|
| |
|
Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 05 Jan 2014 04:03 PM |
@rosenburger
Could you explain the gun.Hit part? Is that supposed to be a part in the tool? |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2014 04:06 PM |
Oh actually I made a mistake sorry let me re write the code for you
bullet.CFrame = CFrame.new(gun.Tip.CFrame.p + (gun.Tip.CFrame.lookVector * 2), mouse.Hit.p) |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2014 04:08 PM |
| So you need to make a part on your gun right infront of the mussle or barrel or whatever, it can be transparent it doesn't matter. Also make bullets and the gun's cancollide property set to false. |
|
|
| Report Abuse |
|
|
|
| 05 Jan 2014 04:11 PM |
| If you need further explaining on how it works I can help. Keep in mind this could be a logical error. You might have set up the code in a way it doesn't work after you move. |
|
|
| Report Abuse |
|
|
Hibobb
|
  |
| Joined: 18 Apr 2010 |
| Total Posts: 2146 |
|
|
| 05 Jan 2014 04:18 PM |
Yeah it still doesnt work. I'll recheck the code and report back later
|
|
|
| Report Abuse |
|
|
| |
|