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: The Distance Formula

Previous Thread :: Next Thread 
Laedere is not online. Laedere
Joined: 17 Jun 2013
Total Posts: 23601
05 Dec 2013 11:25 PM
So I made a distance formula, to find the distance between to given points. Is there any bugs you can find?

cor1 = {1, 2}
cor2 = {3, 4}

x1 = cor1[1]
x2 = cor2[1]
y1 = cor1[2]
y2 = cor2[2]

one = x2-x1
oneone = one^2
two = y2-y1
twoone = two^2

threeone = oneone + twoone
print(math.sqrt(threeone))
Report Abuse
lampwnage121 is not online. lampwnage121
Joined: 20 Oct 2012
Total Posts: 4285
06 Dec 2013 01:16 AM
Erm
Ewww
Report Abuse
ancientblackninja is not online. ancientblackninja
Joined: 05 Aug 2011
Total Posts: 401
06 Dec 2013 02:26 AM
Not Really. But I'm not very good at the "Distance" scripts....
Report Abuse
KiwiMeister is not online. KiwiMeister
Joined: 18 Feb 2010
Total Posts: 1464
06 Dec 2013 03:08 AM
.Magnitude
Report Abuse
einsteinK is not online. einsteinK
Joined: 22 May 2011
Total Posts: 1015
06 Dec 2013 04:09 AM
Like KiWi said:

local a = Vector3.new(x,y,z)
local b = Vector3.new(x,y,z)

local dist = (a-b).magnitude
print("Distance:",dist)

If you want to only use X and Y, use 0 for Z (or leave Z for automatic zero)
Report Abuse
ancientblackninja is not online. ancientblackninja
Joined: 05 Aug 2011
Total Posts: 401
08 Jan 2014 04:42 PM
Hmmm
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