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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Distance Formula vs Magnitude

Previous Thread :: Next Thread 
Thedagz is not online. Thedagz
Joined: 10 Mar 2012
Total Posts: 798
10 Apr 2016 12:17 PM
Is Distance Formula more accurate then magnitude?


Part1 = game.Workspace.Part1.Position
Part2 = game.Workspace.Part2.Position

D = math.sqrt((Part2.x - Part1.x)^2+(Part2.y - Part1.y)^2+(Part2.z - Part1.z)^2)
print(D)
X = (Part1 - Part2).magnitude
print(X)

I'm not sure if something is wrong with my math for the distance formula but I would get different numbers when printing both of them but still very similar.
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
10 Apr 2016 12:42 PM
math.exp?

magnitude is just cleaner i think
Report Abuse
direMitten is not online. direMitten
Joined: 18 Jun 2015
Total Posts: 1294
10 Apr 2016 01:02 PM
It's the same thing, I'm pretty sure. magnitude is as accurate as can be.
Report Abuse
crome60 is not online. crome60
Joined: 22 Nov 2008
Total Posts: 15266
10 Apr 2016 01:04 PM
Magnitude is better.
Report Abuse
John467583 is not online. John467583
Joined: 04 Mar 2010
Total Posts: 116
10 Apr 2016 01:08 PM
both do the same thing, but magnitude is much better because it's so clean
Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
10 Apr 2016 04:06 PM
Technically speaking, both use the distance formula. The reason you're getting different results is that Roblox calculates the magnitude internally using floats whereas in Lua it's all done using doubles (more precise). However the difference is insignificant in almost all cases when dealing with length, and you're better off using the Magnitude property.
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