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 |
|
|
|
| 29 Nov 2013 05:47 PM |
| Yes. It's simple Algebra, use the distance formula, y2-y1/x2-x1 |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 29 Nov 2013 05:50 PM |
It returns only one number so... if mag<50 then |
|
|
| Report Abuse |
|
|
BruceAB12
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
| |
|
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 |
|
|
|
| 29 Nov 2013 05:52 PM |
| No problem, thats what we are here for. |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
|
| 29 Nov 2013 05:56 PM |
| Sorry I have no knowledge on trigonometry. |
|
|
| Report Abuse |
|
|
BruceAB12
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
| |
|
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
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
| |
|
BruceAB12
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
|
| 29 Nov 2013 06:03 PM |
| I have a script spawning 'EnemyBot' |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
|
| 29 Nov 2013 06:20 PM |
| I think of an equation for the size :,( |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 19 Jan 2012 |
| Total Posts: 3238 |
|
|
| 29 Nov 2013 06:25 PM |
| Anyone good at math that could help? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|