Create a spark at precise collision point?

Get help using Construct 2

Post » 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,122
Reputation: 11,268

Post » 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

Post » 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,122
Reputation: 11,268

Post » Mon May 30, 2016 3:36 pm

ImageImageImage
B
71
S
22
G
248
Posts: 3,758
Reputation: 138,067

Post » 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,122
Reputation: 11,268

Post » Mon May 30, 2016 4:14 pm

The simplest method would be to use dummy detector objects.
Image ImageImage
B
171
S
50
G
179
Posts: 8,382
Reputation: 113,458

Post » 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,122
Reputation: 11,268

Post » 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
ImageImageImage
B
71
S
22
G
248
Posts: 3,758
Reputation: 138,067

Post » 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,122
Reputation: 11,268

Post » 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,122
Reputation: 11,268

Next

Return to How do I....?

Who is online

Users browsing this forum: chrisinfinger, YoHoho and 13 guests