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: Gun Engine

Previous Thread :: Next Thread 
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
09 Oct 2015 11:07 PM
Okay so I made a gun engine but It is hard to make it shot..? I am usually good at making tools shot but not really with gun engines. I can do the reload gui, ect but still.

Any help?
Report Abuse
ChiefAlpha is not online. ChiefAlpha
Joined: 01 Oct 2015
Total Posts: 2014
09 Oct 2015 11:10 PM
raycasting
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
09 Oct 2015 11:12 PM
Yeah Ik but for tools it onyl works in studio and not local but idk if that would do the same for engines mine helping me with the code to work?
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
09 Oct 2015 11:37 PM
bump
Report Abuse
SkySpell is not online. SkySpell
Joined: 01 Sep 2008
Total Posts: 1581
09 Oct 2015 11:57 PM
Try making the script server-side?


#code if Name == "SkySpell" then print("The king of kebab & a mediocre scripter.") end
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 11:34 AM
I tried that bfore doesnt work but about the bullet guys any help with it?
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 01:10 PM
bump
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
10 Oct 2015 01:11 PM
your gun will lag if you use cframe animations and filtering disabled


Instance.new("BodyVelocity",SenseiWarrior).velocity = CFrame.new(SenseiWarrior.Torso.Position,YourGirlsDMs.Position).lookVector * 10
Report Abuse
darkstriken is not online. darkstriken
Joined: 23 Oct 2010
Total Posts: 376
10 Oct 2015 01:19 PM
show us the code?
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 02:08 PM
Here's the code I want to make the bullet go out through the handle can someone give me the code? Btw its not a cool its an engine. (Fill in the script through the --//bullet//-- part its the last line) this is a local script

wait(0.2)

-- LOCAL VARIABLES --

local plr = game.Players.LocalPlayer

local cam = game.Workspace.CurrentCamera

local mouse = plr:GetMouse()

local chr = plr.Character

local gun = game.ReplicatedStorage.Guns.ASval

local gun2 = gun:Clone()

local larm = game.ReplicatedStorage.Character.LeftArm

local rarm = game.ReplicatedStorage.Character.RightArm


local torso = chr:WaitForChild("Torso")
local head = chr:WaitForChild("Head")
local L_Arm = chr:WaitForChild("Left Arm")
local R_Arm = chr:WaitForChild("Right Arm")
local neck = chr.Torso:WaitForChild("Neck")
local R_Sh = chr.Torso:WaitForChild("Right Shoulder")
local L_Sh = chr.Torso:WaitForChild("Left Shoulder")

local welds = {}


-- WELDING PROCESS --

for i,v in pairs(gun2:GetChildren()) do
if v:IsA("BasePart") and v.Name ~= "Handle" then
local weld = Instance.new("Weld",v)
weld.Part0 = gun2.Handle
weld.Part1 = v
weld.C0 = gun2.Handle.CFrame:inverse()
weld.C1 = v.CFrame:inverse()
v.Anchored = false
end
gun2.Handle.Anchored = false
end


-- WELDING THE ARMS AND HEAD --

neck.Part1 = nil
R_Sh.Part1 = nil
L_Sh.Part1 = nil

local weld1 = Instance.new("Weld" ,head)
weld1.Part0 = torso
weld1.Part1 = head
weld1.C0 = torso.CFrame
weld1.C1 = torso.CFrame *CFrame.new(0,-1.5,0)
welds[1] = weld1

local weld2 = Instance.new("Weld", L_Arm)
weld2.Part0 = head
weld2.Part1 = L_Arm
weld2.C1 = CFrame.new(1, 0.5, -1) * CFrame.Angles(math.rad(-90), math.rad(30), 0)
welds[2] = weld2

local weld3 = Instance.new("Weld", R_Arm)
weld3.Part0 = head
weld3.Part1 = R_Arm
weld3.C1 = CFrame.new(-0.55, -0.25, -1) * CFrame.Angles(math.rad(-90), 0, 0)
welds[3] = weld3



-- ARM --

local model = Instance.new("Model",cam)
model.Name = "Arms"

local FR_Arm = R_Arm:Clone()
FR_Arm.Parent = model
FR_Arm.BrickColor = BrickColor.new("Pastel brown")
FR_Arm.Size = Vector3.new(-0.2,2.5,-0.2)
FR_Arm.BackSurface = "SmoothNoOutlines"
FR_Arm.BottomSurface = "SmoothNoOutlines"
FR_Arm.FrontSurface = "SmoothNoOutlines"
FR_Arm.LeftSurface = "SmoothNoOutlines"
FR_Arm.RightSurface = "SmoothNoOutlines"
FR_Arm.TopSurface = "SmoothNoOutlines"
FR_Arm.Material = "SmoothPlastic"

local weld4 = Instance.new("Weld", FR_Arm)
weld4.Part0 = R_Arm
weld4.Part1 = FR_Arm
welds[4] = weld4

local FL_Arm = L_Arm:Clone()
FL_Arm.Parent = model
FL_Arm.BrickColor = BrickColor.new("Pastel brown")
FL_Arm.Size = Vector3.new(-0.4,4,-0.4)
FL_Arm.TopSurface = 0
FL_Arm.BottomSurface = 0
FL_Arm.Material = "SmoothPlastic"
FL_Arm.BackSurface = "SmoothNoOutlines"
FL_Arm.BottomSurface = "SmoothNoOutlines"
FL_Arm.FrontSurface = "SmoothNoOutlines"
FL_Arm.LeftSurface = "SmoothNoOutlines"
FL_Arm.RightSurface = "SmoothNoOutlines"
FL_Arm.TopSurface = "SmoothNoOutlines"

local weld5 = Instance.new("Weld", FL_Arm)
weld5.Part0 = L_Arm
weld5.Part1 = FL_Arm
welds[5] = weld5

local weld6 = Instance.new("Weld", gun2.Handle)
weld6.Part0 = R_Arm
weld6.Part1 = gun2.Handle
weld6.C1 = CFrame.new(0,0,0)*CFrame.Angles(math.rad(90),0,0)
welds[6] = weld6

gun2.Parent = game.Workspace


--ARM MOVEMENT--

cam.Changed:connect(function()
print("Changed")
local fr = cam.CoordinateFrame
torso.CFrame = CFrame.new(chr.Torso.Position, Vector3.new((chr.Torso.Position.X*2 - fr.p.X) , (chr.Torso.Position.Y) , (chr.Torso.Position.Z*2 - fr.p.Z)))
welds[1].C1 = CFrame.new(chr.Head.Position , Vector3.new(chr.Head.Position.X*2 - fr.p.X , chr.Head.Position.Y*2 - fr.p.Y , chr.Head.Position.Z*2 - fr.p.Z)):inverse()
welds[1].C0 = chr.Torso.CFrame:inverse()
end)


--//Bullet//--
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 02:13 PM
bump
Report Abuse
RegularTetragon is not online. RegularTetragon
Joined: 10 Oct 2009
Total Posts: 3085
10 Oct 2015 02:21 PM
You need two main components in a gun engine, a server side script, and a local input manager. Handle raycasting serverside and input through context action service on local. Use a remote function to exchange mouse information as needed.
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 02:24 PM
Would you mind helping..?
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 02:32 PM
bump
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 02:37 PM
bump any more help?
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 02:58 PM
f1
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 03:39 PM
f2
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 04:10 PM
f3
Report Abuse
LongKillKreations is not online. LongKillKreations
Joined: 14 Feb 2014
Total Posts: 4502
10 Oct 2015 04:23 PM
You'd want to use raycasting - the algorithms for it have been coded C++ side and is the most efficient way of going about this.

This should help you: http://wiki.roblox.com/index.php/Raycasting
Report Abuse
IanSplodge is not online. IanSplodge
Joined: 13 Aug 2012
Total Posts: 2686
10 Oct 2015 04:28 PM
"Yeah Ik but for tools it onyl works in studio and not local but idk if that would do the same for engines mine helping me with the code to work?"

then make it a tool, remove the tool bar, and make it equip-able in some other way.
Or:
Before Roblox had a RayCasting system, VAK members did this:
http://pastebin.com/rF5cBWXD
Report Abuse
LongKillKreations is not online. LongKillKreations
Joined: 14 Feb 2014
Total Posts: 4502
10 Oct 2015 04:33 PM
Why woudl you use a custom raycasting system that's 100 times less efficient?
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 04:50 PM
mhm ^
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 04:54 PM
@lanludge or watever ur name is that pastebin link how is this gonna help me XD?

function cross(vector1, vector2)
return Vector3.new(vector1.y * vector2.z - vector2.y * vector1.z, vector1.z * vector2.x - vector1.x * vector2.z, vector1.x * vector2.y - vector2.x * vector1.y)
end
function dot(vector1, vector2)
return (vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z)
end
function getLineSphereCollide(linePoint1, lineVector, sphereCenter, radius)
local a = lineVector.x * lineVector.x + lineVector.y * lineVector.y + lineVector.z * lineVector.z
local b = lineVector.x * (linePoint1.x - sphereCenter.x) + lineVector.y * (linePoint1.y - sphereCenter.y) + lineVector.z * (linePoint1.z - sphereCenter.z)
local c = (linePoint1.x - sphereCenter.x) * (linePoint1.x - sphereCenter.x) + (linePoint1.y - sphereCenter.y) * (linePoint1.y - sphereCenter.y) + (linePoint1.z - sphereCenter.z) * (linePoint1.z - sphereCenter.z) - radius * radius
if (a > 0) and (b * b >= a * c) then
local diff = math.sqrt(b * b - a * c)
return ((-b - diff) / a), ((diff - b) / a)
else
return -1, -1
end
end
--Returns hit, position, normal, time
function raycast(model, start, vector, brickFunction)
local hit, normal, time = raycastRecursive(model, start, vector, brickFunction, vector.unit, dot(start, vector.unit))
if (dot(normal, vector) > 0) then
normal = -normal
end
return hit, start + time * vector, normal.unit, time
end
function raycastRecursive(model, start, vector, brickFunction, unitVec, startDist)
if (model.className == "Part") or (model.className == "Seat") or (model.className =="SpawnLocation") then
local range = model.Size.magnitude / 2
local dist = dot(model.Position, unitVec) - startDist
if (dist + range > 0) and (dist - range < vector.magnitude) and ((dist * unitVec + start - model.Position).magnitude < range) and brickFunction(model) then
local halfSize = model.Size / 2
if (model.Shape == Enum.PartType.Ball) then
local time, timeMax = getLineSphereCollide(start, vector, model.Position, halfSize.x)
if (time < 1) and (time >= 0) then
return model, (time * vector + start - model.Position), time
else
return nil, Vector3.new(0, 0, 0), 1
end
elseif (model.Shape == Enum.PartType.Block) then
local time = 1
local cf = model.CFrame - model.Position
local xvec = cf * Vector3.new(1, 0, 0)
local yvec = cf * Vector3.new(0, 1, 0)
local zvec = cf * Vector3.new(0, 0, 1)
local xspd = -dot(xvec, vector)
local yspd = -dot(yvec, vector)
local zspd = -dot(zvec, vector)
local xmin, xmax, ymin, ymax, zmin, zmax = -1
local dotProd = dot(xvec, start - model.Position)
if (xspd ~= 0) then
xmin = (dotProd - halfSize.x) / xspd
xmax = (dotProd + halfSize.x) / xspd
if (xmax < xmin) then
local swap = xmin
xmin = xmax
xmax = swap
end
else
if (math.abs(dotProd) < halfSize.x) then
xmax = 1
xmin = 0
else
return nil, Vector3.new(0, 0, 0), 1
end
end
local dotProd = dot(yvec, start - model.Position)
if (yspd ~= 0) then
ymin = (dotProd - halfSize.y) / yspd
ymax = (dotProd + halfSize.y) / yspd
if (ymax < ymin) then
local swap = ymin
ymin = ymax
ymax = swap
end
else
if (math.abs(dotProd) < halfSize.y) then
ymax = 1
ymin = 0
else
return nil, Vector3.new(0, 0, 0), 1
end
end
local dotProd = dot(zvec, start - model.Position)
if (zspd ~= 0) then
zmin = (dotProd - halfSize.z) / zspd
zmax = (dotProd + halfSize.z) / zspd
if (zmax < zmin) then
local swap = zmin
zmin = zmax
zmax = swap
end
else
if (math.abs(dotProd) < halfSize.z) then
zmax = 1
zmin = 0
else
return nil, Vector3.new(0, 0, 0), 1
end
end
if (xmin <= ymax) and (xmax >= ymin) and (xmin <= zmax) and (xmax >= zmin) and (zmin <= ymax) and (zmax >= ymin) then
local normal = xvec
local min = xmin
if (ymin > min) then
min = ymin
normal = yvec
end
if (zmin > min) then
min = zmin
normal = zvec
end
if (min >= 0) and (min < 1) then
time = min
elseif (xmax > 0) and (ymax > 0) and (zmax > 0) and (min < 0) then
time = 0
normal = Vector3.new(0, 0, 0)
end
return model, normal, time
else
return nil, Vector3.new(0, 0, 0), 1
end
else -- Cylinder
local time = 1
local cf = model.CFrame - model.Position
local xvec = cf * Vector3.new(1, 0, 0)
local xspd = -dot(xvec, vector)
local xmin, xmax = -1
local dotProd = dot(xvec, start - model.Position)
if (xspd ~= 0) then
xmin = (dotProd - halfSize.x) / xspd
xmax = (dotProd + halfSize.x) / xspd
if (xmax < xmin) then
local swap = xmin
xmin = xmax
xmax = swap
end
else
if (math.abs(dotProd) < halfSize.x) then
xmax = 1
xmin = 0
else
return nil, Vector3.new(0, 0, 0), 1
end
end

local relVec = cf:pointToObjectSpace(vector) * Vector3.new(0, 1, 1)
local relPos = model.CFrame:pointToObjectSpace(start) * Vector3.new(0, 1, 1)
local rmin, rmax = getLineSphereCollide(relPos, relVec, Vector3.new(0, 0, 0), halfSize.y)
if (xmin <= rmax) and (xmax >= rmin) and (rmax > 0) then
local normal = xvec
local min = xmin
if (rmin > min) then
min = rmin
normal = cf * (relPos + relVec * min)
end
if (min >= 0) and (min < 1) then
time = min
elseif (xmax > 0) and (rmax > 0) and (min < 0) then
time = 0
normal = Vector3.new(0, 0, 0)
end
return model, normal, time
else
return nil, Vector3.new(0, 0, 0), 1
end
return nil, Vector3.new(0, 0, 0), 1
end
end
return nil, Vector3.new(0, 0, 0), 1
elseif (model.className=="Model") or (model.className=="Workspace") or (model.className=="Pie") or (model.className == "Tool") then
local children=model:GetChildren()
local time=1
local normal=Vector3.new(0, 0, 0)
local hit=nil
for n = 1, #children do
if children[n]~= nil then
local newHit, newNormal, newTime = raycastRecursive(children[n], start, vector, brickFunction, unitVec, startDist)
if (newTime < time) then
time = newTime
hit = newHit
normal = newNormal
end
end
end
return hit, normal, time
else
return nil, Vector3.new(0, 0, 0), 1
end
end
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
10 Oct 2015 05:08 PM
bump m8 can you guys write the raycasting code in the code I gave you?
Report Abuse
YourWillPower is not online. YourWillPower
Joined: 14 Jul 2014
Total Posts: 535
11 Oct 2015 11:03 AM
^
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