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: Raycast Spread?

Previous Thread :: Next Thread 
HailMontgomery is not online. HailMontgomery
Joined: 09 Aug 2011
Total Posts: 8257
24 Apr 2016 09:12 PM
I am using the raycast script from the Roblox Wiki, and it doesn't seem to include any spread. Would this be easy to implement? How would I go about doing this?

Your reply was the most disappointing thing since my son.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Apr 2016 09:24 PM
You should probably use CFrames for rotation, that would be the easiest way.
Specify DegreesSpreadFromCenter, OriginVector3, TargetVector3, and Distance.


local Direction = CFrame.new(OriginVector3, TargetVector3) * CFrame.Angles(0, 0, math.random()*math.pi*2) * CFrame.Angles(math.random()*math.rad(DegreesSpreadFromCenter), 0, 0)
local R Ray.new(OriginVector3, Direction.lookVector*Distance)

Use R in your raycasting.
Report Abuse
DogeKip is not online. DogeKip
Joined: 06 Mar 2011
Total Posts: 6860
24 Apr 2016 09:43 PM
This is how I did it

local distFirst = (mouse.Hit.p - tool.Barrel.CFrame.p).magnitude
local spread = Vector3.new(math.random()*2-1,math.random()*2-1,math.random()*2-1)*distFirst * .012

[Redacted]
Report Abuse
DogeKip is not online. DogeKip
Joined: 06 Mar 2011
Total Posts: 6860
24 Apr 2016 09:45 PM
I forgot the raycast, here:

local distFirst = (mouse.Hit.p - tool.Barrel.CFrame.p).magnitude
local spread = Vector3.new(math.random()*2-1,math.random()*2-1,math.random()*2-1)*distFirst * .012
local rayCast = Ray.new(tool.Barrel.Position, ((mouse.Hit.p - tool.Barrel.CFrame.p)+spread).unit*300)

[Redacted]
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
24 Apr 2016 09:46 PM
But that way, Doge, it spreads over the same area around the target, not same angles.
Report Abuse
DogeKip is not online. DogeKip
Joined: 06 Mar 2011
Total Posts: 6860
24 Apr 2016 09:49 PM
"But that way, Doge, it spreads over the same area around the target, not same angles."

You're wrong. You missed the part where I calculated the total magnitude and multiplied them out. This produces a relative spread rather than an absolute spread.

[Redacted]
Report Abuse
HailMontgomery is not online. HailMontgomery
Joined: 09 Aug 2011
Total Posts: 8257
24 Apr 2016 10:47 PM
Thanks Doge.

Your reply was the most disappointing thing since my son.
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