9 posts
• Page **1** of **1**

R0J0hound wrote:It's from the origin of the object that is usually centered in the image editor. You could always add an imagepoint and use Sprite.imagepointx(1) instead of sprite.x.

Yes, the problem is that would only be for one point, I was hoping to use an expression that would be effectively the same as "if overlapping", and I could then have the distance as short as possible from the edge, rather than the centre. Is there a was of checking an overlap entirely in the expression editor?

**Posts:**1,120**Reputation:**11,259

B

41
S

12
G

14
**Posts:**171**Reputation:**3,329

B

30
S

9
G

3
gameglaux wrote:Use the dimensions of the object: sprite.x + (sprite.width / 2)

So, for instance:

- Code: Select all
`distance(tracers.HitX,tracers.HitY,badguy.X+badguy.width / 2,badguy.y+badguy.height / 2)`

Less than 16

I can't get it to work evenly, I mean, that 16 could be, say, less than 2 to test for an overlap, couldn't it?

**Posts:**1,120**Reputation:**11,259

B

41
S

12
G

14
The distance() expression only gives you the distance between two points. To get the closest distance between a point and a shape it will be more involved. Take the example of a square shape, you'll need to get the distance from all the corners and all the edges and pick the lowest value.

Basically you'd setup the imagepoints on your object like this:

Where 0 is the origin.

Then to calculate the distances you'd use the distance() expression to get the distance to a point, and for the distance to a line you'd use a vector dot product to see if the the projected point is on the line, then a vector cross product is used to get the distance.

Example here:

https://dl.dropboxusercontent.com/u/542 ... _dist.capx

Now if that is too much math you can go for an approximate solution: Put a lot of instances all around the shape you want to get the closest distance to. It should look like dots going around the object's edge, the closer together the better. Then you can then do an event like this:

dotSprite: pick closest to (mouse.x, mouse.y)

--- set text to distance(dotSprite.x, dotSprite.y, mouse.x, mouse.y)

Basically you'd setup the imagepoints on your object like this:

- Code: Select all
`0---1`

| |

3---2

Where 0 is the origin.

Then to calculate the distances you'd use the distance() expression to get the distance to a point, and for the distance to a line you'd use a vector dot product to see if the the projected point is on the line, then a vector cross product is used to get the distance.

Example here:

https://dl.dropboxusercontent.com/u/542 ... _dist.capx

Now if that is too much math you can go for an approximate solution: Put a lot of instances all around the shape you want to get the closest distance to. It should look like dots going around the object's edge, the closer together the better. Then you can then do an event like this:

dotSprite: pick closest to (mouse.x, mouse.y)

--- set text to distance(dotSprite.x, dotSprite.y, mouse.x, mouse.y)

**Posts:**5,295**Reputation:**71,501

B

92
S

32
G

110
R0J0hound wrote:The distance() expression only gives you the distance between two points. To get the closest distance between a point and a shape it will be more involved. Take the example of a square shape, you'll need to get the distance from all the corners and all the edges and pick the lowest value.

Basically you'd setup the imagepoints on your object like this:

- Code: Select all
`0---1`

| |

3---2

Where 0 is the origin.

Then to calculate the distances you'd use the distance() expression to get the distance to a point, and for the distance to a line you'd use a vector dot product to see if the the projected point is on the line, then a vector cross product is used to get the distance.

Example here:

https://dl.dropboxusercontent.com/u/542 ... _dist.capx

Now if that is too much math you can go for an approximate solution: Put a lot of instances all around the shape you want to get the closest distance to. It should look like dots going around the object's edge, the closer together the better. Then you can then do an event like this:

dotSprite: pick closest to (mouse.x, mouse.y)

--- set text to distance(dotSprite.x, dotSprite.y, mouse.x, mouse.y)

I see, so maybe distance isn't so much what I'm looking for? What I need really is an expression that tests if a points x/y is overlapping an instance. i know objects can be testing if they're overlapping, but could a point be tested with system expressions?

**Posts:**1,120**Reputation:**11,259

B

41
S

12
G

14
**Posts:**2,230**Reputation:**44,892

B

74
S

20
G

71
Colludium wrote:Pick overlapping point system condition could help.

I feel so stupid, thanks for pointing that one out, I've even seen it and didn't think to try it!

That seems to work to check for an overlap within the shape at any point. Or is there a more efficient way I can test for this using one event?

**Posts:**1,120**Reputation:**11,259

B

41
S

12
G

14
9 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: Armench, Jackriduk, kiki4construct and 29 guests |