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: Magnitude in GUIS?

Previous Thread :: Next Thread 
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:46 PM
Is it possible to calculate how far a frame is from another?
Report Abuse
VesuviusSentinel is not online. VesuviusSentinel
Joined: 23 Oct 2013
Total Posts: 571
29 Nov 2013 05:47 PM
Yes. It's simple Algebra, use the distance formula, y2-y1/x2-x1
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:48 PM
Oh yeah I remember

local mag1 = a.Position.X - b.Position.X
local mag2 = a.Position.Y - b.Position.Y

I was doing this
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:49 PM
local mag1 = a.Position.X - b.Position.X
local mag2 = a.Position.Y - b.Position.Y
local mag = mag2/mag1
if mag -- This is where I need help :P
Report Abuse
VesuviusSentinel is not online. VesuviusSentinel
Joined: 23 Oct 2013
Total Posts: 571
29 Nov 2013 05:50 PM
It returns only one number so...
if mag<50 then
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:51 PM
Thank you kind sir.
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:52 PM
Wait would it mater if the position is scale instead of offset?
Report Abuse
VesuviusSentinel is not online. VesuviusSentinel
Joined: 23 Oct 2013
Total Posts: 571
29 Nov 2013 05:52 PM
No problem, thats what we are here for.
Report Abuse
Sorexus is not online. Sorexus
Joined: 13 Aug 2013
Total Posts: 124
29 Nov 2013 05:52 PM
This is where trig comes in, as long as you know the pythagorean theorem, you should be able to do it. But here:

distance = math.sqrt((mag1^2) + (mag1^2))
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:55 PM
You just confused me so would I do this

if mag < 50 then

or...

if distance < 50 then
Report Abuse
Sorexus is not online. Sorexus
Joined: 13 Aug 2013
Total Posts: 124
29 Nov 2013 05:56 PM
distance

You did

mag2/mag1 -- Which is the slope not the distance
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:56 PM
Sorry I have no knowledge on trigonometry.
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 05:56 PM
Ah I see thank you :D
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:00 PM
repeat
wait(.01)
a = script.Parent
b = script.Parent:WaitForChild("EnemyBot")
local mag1 = a.Position.X - b.Position.X
local mag2 = a.Position.Y - b.Position.Y
local mag = math.sqrt((mag1^2) + (mag1^2))
if mag < 50 then
print("Enemy is close")
end
until Collision(a,b) -- This is a global function
script.Parent:remove()


Any reasons why this isn't working?
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:01 PM
I get no output.
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:03 PM
I have a script spawning 'EnemyBot'
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
29 Nov 2013 06:05 PM
You are going to get problems since you are not comparing the size as well.

Your script will work fine if the size of everything is all 0
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:20 PM
I think of an equation for the size :,(
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:22 PM
(((((first.AbsolutePosition.X+(first.AbsoluteSize.X/2))-(second.AbsolutePosition.X+(second.AbsoluteSize.X/2)))^2) + (((first.AbsolutePosition.Y+(first.AbsoluteSize.X/2))-(second.AbsolutePosition.Y+(second.AbsoluteSize.X/2)))^2)^0.5)

But i'm assuming it would be similar to the one used in my collision engine^
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:25 PM
Anyone good at math that could help?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
29 Nov 2013 06:28 PM
I am but my thinking cap is not on, I'm busy playing a game (fgunz c;)
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:30 PM
So am I, but when I see lots of numbers and equations my head starts hurting.
Report Abuse
Sorexus is not online. Sorexus
Joined: 13 Aug 2013
Total Posts: 124
29 Nov 2013 06:31 PM
I'm hungry, sorry. And I'm too lazy D:
Report Abuse
monstre180 is not online. monstre180
Joined: 02 May 2009
Total Posts: 110
29 Nov 2013 06:38 PM
Heres how you find distance between 2 points:

dx=x2-x1
dy=y2-y1
dist=sqrt((dx*dx)+(dy*dy))
Report Abuse
BruceAB12 is not online. BruceAB12
Joined: 19 Jan 2012
Total Posts: 3238
29 Nov 2013 06:56 PM
repeat
wait(.01)
a = script.Parent
b = script.Parent:WaitForChild("EnemyBot")
local mag1 = a.AbsolutePosition.X - b.AbsolutePosition.X
local mag2 = a.AbsolutePosition.Y - b.AbsolutePosition.Y
local size1 = a.AbsoluteSize.X - b.AbsoluteSize.X
local size2 = a.AbsoluteSize.Y - b.AbsoluteSize.Y
local mag = math.sqrt((mag1^2) + (mag1^2))
local mag2 = math.sqrt(size1 * size1)+ (size2 * size2)
if mag < 50 then
print("Enemy is close")
end
until Collision(a,b)
print("Sentry is gone")
script.Parent:remove()


So now what would I put for the if statement?
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