# Events based on the speed of a collision

Get help using Construct 2

### » Fri Jan 20, 2012 4:41 am

I'd like to be able to know what the force of a collision is to determine if it was just a "bump" or enough to trigger a "kill" etc.

If you think of Angry Birds... a light tap does nothing to a pig... a medium hit gives a black eye... and enough hits or a big hit destroys the pig.

In a similar way in my physics based game I'd like to know how hard an impact is.

If there is a way to do this I'd love to know (legit or a hack ;-)

Cheers,
Steve
B
7
S
2
G
4
Posts: 9
Reputation: 2,963

### » Fri Jan 20, 2012 4:53 am

You can use the AngularVelocity expression of the physics object to tell how fast it's going. Test what the value is upon collision, and from there you decide how high it has to be to be a light, medium, or hard hit.

Lemme know if you need an example whipped up -- or if this doesn't work. It might not, since I don't actually use the physics behavior myself.
B
20
S
9
G
6
Posts: 607
Reputation: 6,117

### » Fri Jan 20, 2012 9:49 am

'AngularVelocity' is the speed the object is rotating at - to get the overall speed use distance(0, 0, Sprite.Physics.VectorX, Sprite.Physics.VectorY). Other behaviors have a 'speed' expression. You just need to check this in the collision event.
Scirra Founder
B
413
S
244
G
92
Posts: 25,104
Reputation: 199,850

### » Mon Jan 23, 2012 2:41 am

thanks for the ideas... i'm guessing that the distance(0, 0, Sprite.Physics.VectorX, Sprite.Physics.VectorY) is what I need... the only trick I have now... (and sorry for being so naive) is where can I use this expression?
B
7
S
2
G
4
Posts: 9
Reputation: 2,963

### » Mon Jan 23, 2012 4:57 pm

You can use expressions about wherevere you have a text field.

So you can use expressions in the system condition "compare", in actions, etc...

I guess what you could use would be system: compare two values, put distance(0, 0, Sprite.Physics.VectorX, Sprite.Physics.VectorY) in the first field, and a comparison value in the second field (> 0 for example, would mean that the action would happen anytime your object is moving, since its velocity is not 0).
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
307
S
126
G
99
Posts: 7,385
Reputation: 73,871

### » Wed Jan 25, 2012 1:34 am

Thanks for the tips... PS you did mean "VelocityX, and VelocityY" vs. VectorX, and VectorY... correct?
B
7
S
2
G
4
Posts: 9
Reputation: 2,963

### » Wed Jan 25, 2012 2:28 am

Indeed.
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
307
S
126
G
99
Posts: 7,385
Reputation: 73,871

Return to How do I....?

### Who is online

Users browsing this forum: Luvkraft and 25 guests