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
 

Re: How do people make projectilez wid raycast?

Previous Thread :: Next Thread 
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
07 Aug 2013 04:45 PM
I usually use body objects, template pls
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
07 Aug 2013 04:46 PM
Ehhhhhh...

Okay here's my code

function raycast(startPoint, endPoint, ign)
vector = (endPoint - startPoint)
if vector.magnitude < 1000 then
hit, position = game.Workspace:FindPartOnRay(Ray.new(startPoint, vector), ign)
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 == "Gun" and hit.Parent ~= gun 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" then
vector = (endPoint - position)
hit, position = raycast(position, vector, hit)
end
end
return hit, position
end
return nil
end

function fire(aim)
gun.Handle.Fire.Pitch = (math.random(-5,5)/30) + 1.25
gun.Handle.Fire:Play()
bullet = Instance.new("Part")
bullet.Name, bullet.BrickColor, bullet.Anchored, bullet.CanCollide, bullet.TopSurface, bullet.BottomSurface, bullet.FormFactor, bullet.Transparency, bullet.Size = "Bullet", game.Players.LocalPlayer.TeamColor, true, false, 0, 0, "Custom", bulletTransparency, Vector3.new(1, 1, 1)
if bulletMesh then
mesh = Instance.new("SpecialMesh")
mesh.Name, mesh.MeshType, mesh.Scale, mesh.Parent = "BulletMesh", "Brick", Vector3.new(meshScale, meshScale, 1), bullet
end
totalDistance = 0
lengthDistance = -rayLength/0.5
startPoint= gun.Handle.CFrame*Vector3.new(-3, -0.6, 0)
direction = (aim - startPoint)
cframe = CFrame.new(startPoint, direction + startPoint)
vector = startPoint + (direction.Unit*999)
if (startPoint - vector).magnitude < 1000 then
hit, position = raycast(startPoint, vector, game.Players.LocalPlayer.Character)
bullet.Parent = game.Workspace
if hit ~= nil then
if hit.ClassName == "Model" then
damage = math.random(baseDamage - (baseDamage*0.25), baseDamage + (baseDamage*0.25))
if hit.Name == "Head" then damage = damage*1.2
elseif hit.Name == "Torso" then damage = damage*1.1 end
if hit:FindFirstChild("Humanoid") ~= nil then
hit.Humanoid.Health = hit.Humanoid.Health - damage
end
end
distance = (startPoint - position).magnitude
bullet.Size = Vector3.new(0.2, 0.2, distance)
bullet.CFrame = cframe*CFrame.new(0, 0, -distance/2)
else
bullet.Size = Vector3.new(0.15, 0.15, rayLength)
bullet.CFrame = cframe*CFrame.new(0, 0, -rayLength/2)
end
if game:FindFirstChild("Debris") == nil then
debris = Instance.new("Debris")
debris.Parent = game
end
game.Debris:AddItem(bullet, 0.025)
end
end
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
07 Aug 2013 04:47 PM
local startpos = lolurface
local endpos = lolurmouse
local velocity = lolurspeedmultipliedbyurdirectionfromstarttoend
local lastpos = startpos
local time = tick()

for i = 1, 100 do
local newpos = startpos + (tick() - time) * velocity
raycastpl0x
if lolhit then break end
end
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
07 Aug 2013 04:48 PM
Mine is more of a template than yours, so I win.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
07 Aug 2013 04:48 PM
Bro i like u

I will study ur code evn if its much more complex than my life
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
07 Aug 2013 04:49 PM
Here's some freshly brewed pseudocode:

make raycast
make part
part follow raycast
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
07 Aug 2013 04:49 PM
Srsly, get notunknown a pony
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
07 Aug 2013 04:49 PM
My code

Is 150% times more lolnou

Use it
Report Abuse
Xtreme101 is not online. Xtreme101
Joined: 03 Jan 2009
Total Posts: 4385
07 Aug 2013 04:51 PM
Well crap Notunknown99, you win again.

*Shakes fist in jealously*
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
07 Aug 2013 04:58 PM
Notunknown is just there with his template thinking im smart enough to know wut hes talking bout lal


Since when did i reach 6k posts xD?
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
07 Aug 2013 04:59 PM
Since when you posted your 6000th post.
Report Abuse
Infocus is not online. Infocus
Joined: 28 Apr 2011
Total Posts: 8022
07 Aug 2013 05:01 PM
I am, but a man. Nor i am a robot

-Abraham lincoln
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