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: Calculating the length of a ray?

Previous Thread :: Next Thread 
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
04 Jun 2016 05:14 PM
So I've made my ray between a part, and a Vector.new(0,1,0).unit

How can I determine the distance between these things by using the ray?


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
04 Jun 2016 05:16 PM
After reading this twice, it's a bad question.

Basically what I'm trying to do is calculate how many "steps" I'd need a falling object to descend in order to reach ground level (ground level will vary constantly)

Should I be using a ray for this in the first place?


Report Abuse
Void_Optics is not online. Void_Optics
Joined: 21 Mar 2016
Total Posts: 286
04 Jun 2016 05:17 PM
If the ray makes contact with something, using FindPartOnRay (?) (thats not the name, look it up bc i dont remember) and the position value on it, you can use magnitude between the position and the origin of the ray
Report Abuse
Void_Optics is not online. Void_Optics
Joined: 21 Mar 2016
Total Posts: 286
04 Jun 2016 05:17 PM
yes, you do want a ray for this
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
04 Jun 2016 05:20 PM
So, the ground is made of Terrain, I would say something like...

local ray = Ray.new(Model1.PrimaryPart.CFrame.p,(Vector3.new(0,1,0).unit))

local hit, position = workspace:FindPartOnRay(ray, p.Character)
if hit:IsA'BasePart' then
-- here, how do I determine distance to the end of the ray?
end


Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
04 Jun 2016 05:21 PM
And also, do I have to say

if hit:IsA'BasePart' or hit:IsA'Terrain' then
-- do stuff
end


?


Report Abuse
Void_Optics is not online. Void_Optics
Joined: 21 Mar 2016
Total Posts: 286
04 Jun 2016 05:22 PM
print((Model1.PrimaryPart.CFrame.p-position).magnitude)
Report Abuse
Void_Optics is not online. Void_Optics
Joined: 21 Mar 2016
Total Posts: 286
04 Jun 2016 05:23 PM
And if the className for terrain is "Terrain" then yeah use that
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
04 Jun 2016 05:24 PM
The classname for Unions is UnionOperation, and the classname for Parts is Part, but they still somehow identify as a BasePart.


Report Abuse
Void_Optics is not online. Void_Optics
Joined: 21 Mar 2016
Total Posts: 286
04 Jun 2016 05:26 PM
Then have it print the className of the terrain, then just say IsA(whatever it tells u it is)
Report Abuse
ray_1 is not online. ray_1
Joined: 18 Feb 2011
Total Posts: 464
04 Jun 2016 05:28 PM
IsA() will take into account of inherited classes, and pretty much all types of parts inherit from BasePart. Also, Terrain inherits from BasePart as well so you only need IsA("BasePart")


Recommended username: PainfulRay_1


Report Abuse
Void_Optics is not online. Void_Optics
Joined: 21 Mar 2016
Total Posts: 286
04 Jun 2016 05:29 PM
^
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
04 Jun 2016 05:29 PM
Thanks, I thought so but wasn't sure.


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