generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Help with rays and cframe

Previous Thread :: Next Thread 
iondriver is not online. 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
IllegallyBlind is not online. IllegallyBlind
Joined: 07 Nov 2010
Total Posts: 1691
30 Sep 2015 01:47 PM
die


Instance.new("BodyThrust" , Illegallyblind.Pelvis)
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
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 is not online. 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 is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
30 Sep 2015 08:01 PM
Bump
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
30 Sep 2015 08:38 PM
Bump
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
30 Sep 2015 10:52 PM
Bump

Anybody?
Report Abuse
iondriver is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image