iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 30 Sep 2015 01:38 PM |
Hello all,
I am trying to make it so that the bullets of my gun line up with the scope on the gun. This is what I have. --on mouse down function onMouse1Down() local inHand = equ.Value local vals = inHand.Values if aiming == true then local muz = inHand.Muzzel local pos = targetingComputer(inHand) local cf = CFrame.new(muz.Position, pos) fire:FireServer(cf, vals.Velocity.Value, vals.Range.Value, equ.Type.Value, vals.Damage.Value) else local cf = CFrame.new(inHand.Muzzel.Position, mse.Hit.p) fire:FireServer(cf, vals.Velocity.Value, vals.Range.Value, equ.Type.Value, vals.Damage.Value) end end --casting the ray and looking for hits function targetingComputer (gun) local ignoreTable = {char, m, prim.Value, sec.Value} local s = gun.Sight local t = gun.Targ local start = s.Position local cf = s.CFrame local direct = (s.Position - t.Position).Unit * gun.Values.Range.Value local ray = Ray.new(start, direct) local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreTable) return pos end -- Launch the bolt function Launch (plr, muz, vel, ran, type, Dam) local c = bolt:Clone() local cen = c.Part c:SetPrimaryPartCFrame(muz*CFrame.Angles(math.rad(90),0,0)) c.Center.Propulsion.Force = c.Center.Propulsion.Force + (muz.lookVector*vel) c.Center.Gyro.CFrame = c.Center.CFrame c.Parent = game.Workspace c.Center:SetNetworkOwner(plr) cen.Touched:connect(function (hit) if hit.CanCollide == true then local hum = hit.Parent:FindFirstChild("Humanoid") if hum and hit.Parent ~= plr.Character then hum:TakeDamage(Dam) end c:Destroy() end end) end
Basically what is supposed to happen is a ray is shot through the scope of the gun, and either the position of the hit or the end of the ray is returned. This is used to make a starting CFrame for the bullet, which is then created. The issue I am having is that the lookvector gets all messed up. The bullet always flies towards on point. Any Help is appreciated
Thanks,
Iondriver |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 01:47 PM |
die
Instance.new("BodyThrust" , Illegallyblind.Pelvis) |
|
|
| Report Abuse |
|
|
|
| 30 Sep 2015 01:56 PM |
post error.
people can easily help with debugging but this requires testing and doesnt instantly give us a basic concept of whats going wrong. |
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 30 Sep 2015 06:52 PM |
| the script compiles without error. The ray casting also works properly. The issue I have is that when the gun fires, the bullet always travels towards the same point, no matter which way the gun is facing. |
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
| |
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
| |
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
| |
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 01 Oct 2015 09:50 AM |
bump.
Any idea where my logic is messed up? |
|
|
| Report Abuse |
|
|
FlyNormal
|
  |
| Joined: 30 Sep 2015 |
| Total Posts: 344 |
|
|
| 01 Oct 2015 09:57 AM |
| So the issue is that the ray is fired to where you hit with your mouse and not the scope's lookVector? |
|
|
| Report Abuse |
|
|
iondriver
|
  |
| Joined: 18 Nov 2012 |
| Total Posts: 757 |
|
|
| 01 Oct 2015 01:37 PM |
| lol, I fixed. I need to start the ray at the camera's position. |
|
|
| Report Abuse |
|
|