# Create a spark at precise collision point?

Get help using Construct 2

### » Mon May 30, 2016 2:55 pm

I've been looking through thread after thread and there doesn't seem to be an easy way of retrieving the exact point where two objects (say, a sprite and a tiled background) collide. I want to create a little spark when my car touched a wall, but I want the spark to occur at the exact point on the car body where it hits the wall on the correct side of the car, at the bonnet or rear, etc. Is this possible with just an expression?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Mon May 30, 2016 3:09 pm

I remember something for two square objects.....x=(square1.x+square2.x/2)...y=(square1.y+square2.y/2) , could be usefull
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

### » Mon May 30, 2016 3:16 pm

granpa wrote:I remember something for two square objects.....x=(square1.x+square2.x/2)...y=(square1.y+square2.y/2) , could be usefull

Hmm, trying this, it's only creating the spark now and then, not sure mathematically what it's doing exactly?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Mon May 30, 2016 3:36 pm

B
71
S
22
G
288
Posts: 3,862
Reputation: 158,430

### » Mon May 30, 2016 3:58 pm

I noticed, isn't there a plugin that could do it, without using physics? Just to be able to place the spark on the correct side of the rectangle would be good enough.
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Mon May 30, 2016 4:14 pm

The simplest method would be to use dummy detector objects.
B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

### » Mon May 30, 2016 4:23 pm

newt wrote:The simplest method would be to use dummy detector objects.

Yeah, thats what I'm thinking. Does pinning 4 detectors cause a big increase in resources?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Mon May 30, 2016 4:25 pm

granpa's code (almost) does it (brackets were in the wrong place):

x=(square1.x+square2.x)/2
y=(square1.y+square2.y)/2
B
71
S
22
G
288
Posts: 3,862
Reputation: 158,430

### » Mon May 30, 2016 4:26 pm

newt wrote:The simplest method would be to use dummy detector objects.

Sorry, I forgot to ask, is there an efficient way of creating the 4 detectors, and pinning them to the sprite at the different positions?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

### » Mon May 30, 2016 4:31 pm

blackhornet wrote:granpa's code (almost) does it (brackets were in the wrong place):

x=(square1.x+square2.x)/2
y=(square1.y+square2.y)/2

Hmm, this doesn't seem to create the sparks at all now, before they created by at the same position as the car, but now they don't seem to be there? I just realized, I'm using tilemaps, so will I need to calculate it for the tile the car collides with?
B
41
S
12
G
14
Posts: 1,124
Reputation: 11,286

Next