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 » Scripting Helpers
Home Search
 

A ray that can check multiple hits?

Previous Thread :: Next Thread 
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
14 Sep 2013 07:44 PM
I've scripted a basic beam weapon that, as is stands, can damage players via a raycasting function. The beam is upgradable, however, and I want to add an upgrade where the ray goes THROUGH players, ending on the first solid object it hits that isn't a character - but can still perform the hitcheck to damage them. Is this possible? Do I need to change the ray function to ignore characters?

Code snippets (the whole thing's a localscript)

local player = game.Players.LocalPlayer
local char = player.Character
player:WaitForChild("DataBin")
local bin = player.DataBin
local mouse = player:GetMouse()

local ug = {
["dmg"] = bin.BeamDamage.Value,
["col"] = bin.BeamColor.Value,
["typ"] = bin.BeamType.Value,
["grav"] = bin.GravityChip.Value,
["frz"] = bin.Ice.Value,
["pls"] = bin.Plasma.Value,
["rc"] = bin.ReactorChip.Value,
["scr"] = bin.ScrewAttack.Value,
["sd"] = bin.SuperDash.Value,
["sh"] = bin.Superheat.Value,
["cd"] = bin.ChargeRate.Value
}

v3 = Vector3.new
i_n = Instance.new
c3 = Color3.new
bc = BrickColor.new
cfn = CFrame.new

local WorldToCellFunction = Workspace.Terrain.WorldToCellPreferSolid
local GetCellFunction = Workspace.Terrain.GetCell

function RayIgnoreCheck(hit, pos)
if hit then
if hit.Transparency >= .9 or hit.CanCollide == false or
hit.Name == "Effect" or hit.Name == "Missile" or hit.Name == "Bullet" or
hit.Parent:IsA("Tool") or hit:IsDescendantOf(MyCharacter) then
return true
elseif hit:IsA('Terrain') and pos then
local cellPos = WorldToCellFunction(Workspace.Terrain, pos)
if cellPos then
local cellMat = GetCellFunction(Workspace.Terrain, cellPos.x, cellPos.y, cellPos.z)
if cellMat and cellMat == Enum.CellMaterial.Water then
return true
end
end
end
end
return false
end

function RayCast(startPos, vec, rayLength)
local hitObject, hitPos = game.Workspace:FindPartOnRay(Ray.new(startPos + (vec * .01), vec * rayLength), Handle)
if hitObject and hitPos then
local distance = (hitPos - startPos).magnitude
if RayIgnoreCheck(hitObject, hitPos) and distance > 0 then
return RayCast(hitPos, vec, distance)
end
end
return hitObject, hitPos
end


Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
14 Sep 2013 07:55 PM
You can call the raycast function within the raycast function.
Report Abuse
Geomaster is not online. Geomaster
Joined: 05 Jul 2008
Total Posts: 1480
14 Sep 2013 07:56 PM
RAYCEPTION..

Sorry, but I'll ask you to show me an example, I'm more lost than after watching a full season of Lost.
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
14 Sep 2013 08:08 PM
My own code:

function raycast(startPoint, endPoint, ign)
vector = (endPoint - startPoint)
if vector.magnitude < rayLength + 1 then
hit, position = game.Workspace:FindPartOnRay(Ray.new(startPoint, vector), domain)
if hit and position then
player = game.Players:FindFirstChild(hit.Parent.Name)
if hit.Parent.ClassName == "Hat" then
if hit.Parent.Parent ~= nil then
if hit.Parent.Parent:findFirstChild("Humanoid")~= nil then
return hit.Parent.Parent, position
end
end
elseif player ~= nil or hit.Parent.Name == "Character" then
return hit.Parent, position
elseif (hit.Parent.Name == "Rifle" and hit.Parent ~= firearms[1]) or (hit.Parent.Name == "Pistol" and hit.Parent ~= firearms[2]) or (hit.Parent.Name == "Sword" and hit.Parent ~= sword) or (hit.Parent.Name == "Knife" and hit.Parent ~= knife) or (hit.Parent.Name == "Watch" and hit.Parent ~= watch) then
if hit.Parent.Status.Owner.Value ~= nil then
return hit.Parent.Status.Owner.Value, position
end
elseif hit.Transparency == 1 or hit.Name == "Bullet" or hit.Name == "Hole" or hit.Name:sub(1, 5) == "Window" or hit.Name:sub(1, 5) == "Water" then
vector = (endPoint - position)
hit, position = raycast(position, vector, hit) -- HERE! IT'S RIGHT HERE!!!!!! AHHHHHHHH
end
end
return hit, position
end
return nil
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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