Force of impact

For questions about using Classic.

Post » Fri Nov 28, 2008 7:30 pm

I'm using the physics behaviour and basically want one of my objects to be damaged on impact with other objects, where the amount of damage is proportional to the force of the impact.

I guess my problem is that I don't really know what I mean by force of impact. My best guess is either the change in momentum of the object or the change in energy, before and after the collision.

I can't get it to act the way I want, for example, one problem I've had every time was that if, say, I wanted an object to be hurt when it fell from a big height, then a lot of the time when it was pushed along the floor it got hurt just as much. (usually when the floor was a downward slope).

I can see the reason for this happening but can't think of a way around it,
my event was an attempt at the kinetic energy (1/2 mv^2):

on collision -> subtract (sprite1.mass+sprite2.mass)*((sprite1.xvel-sprite2.xvel)^2+(sprite1.yvel-sprite2.yvel)^2) from health

So here when the object was moving fast along the floor it wasn't slowing down and kept losing health proportional to speed. (there sprite1 was the object and sprite2 the floor).

I'm guessing I need some way of resolving the angle of the collision, not sure how to go about this either though. :?

any ideas?
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Fri Nov 28, 2008 10:01 pm

Maybe use function that'll decrease vitality only when damage is big enough:
v < k -> f(v) = 0
v >= k -> f(v) = kmv

You can check condition like "v >= k" inside expression.

So doing damage would looke like this:
Add to ('damage') value:
[code:3eve90fb](obj('v') >= obj('k')) * obj('k') * obj('m') * obj('v')[/code:3eve90fb]

(obj('v') >= obj('k')) - this'll get value 1 or 0 depending on its logical value.

Appaerently, syntax Cond?ValIfTrue:ValIfFalse crashes at my machine. Is this a bug?

These above aren't examples of how does formula should look like. AFAIR kinethic energy has part coming from its linear velocity (1/2 * m * v^2) and angular velocity (1/2 * I * w^2). If you have rotating object, collision with ground makes damage proportional to Sum of there two elements.
B
6
S
3
G
6
Posts: 219
Reputation: 3,013

Post » Fri Nov 28, 2008 11:29 pm

[quote="BROO":vgaj2o57]Appaerently, syntax Cond?ValIfTrue:ValIfFalse crashes at my machine. Is this a bug?[/quote:vgaj2o57]
Yeah, crashes are always bugs :P What expression are you using that crashes?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Nov 29, 2008 3:50 pm

[code:vwitaakp]1. Always
-> Sprite: Add (Sprite('myVal') > 0) ? 1 : 0 to 'myVal'[/code:vwitaakp]

Even if I write (2 > 0) ? 1 : 0
It goes wrong.
B
6
S
3
G
6
Posts: 219
Reputation: 3,013

Post » Sat Nov 29, 2008 4:02 pm

Even if it only damages if over a certain value (k), you still get that problem. If the object is moving along the floor at some speed over k, it damages it like before.

I guess its to do with the change of energy before and after the collision???

In this situation when using the physics behaviour and on collision event, will retrieving the velocity give me the velocity after the collision?
B
2
S
2
G
5
Posts: 236
Reputation: 2,122

Post » Sat Nov 29, 2008 5:10 pm

Technically it probably does relate to the energy before and after a collision, but you can fake it since in the physics engine it'll probably always be proportional to the momentum at the point of the collision. Momentum is speed * mass so you only really need something based off that, I think.

However, you probably want the relative speed for calculating damage. If you're going at 1000 px/sec to the right, and you collide with something going right at 900 px/sec, that's a 100 px/sec collision speed, not 1000 px/sec collision speed (factor of 10 difference!).

The result formula for A colliding with B (pseudocode) probably looks something like

0.1 * distance(0, 0, A.XVelocity - B.XVelocity, A.YVelocity - B.YVelocity) * A.Mass

where 0.1 is your 'fudge factor' (since a damage value just involving speed and mass is probably a really big number)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sat Nov 29, 2008 9:13 pm

[url:10mcveuf]http://www.quotecats.com/what/gravplat1.cap[/url:10mcveuf]
In that cap, the last event is the damage one.
controls are W A D Q and E.

If you run down a hill it hurts you still, none of the formula changes help that. It's why I think it must need to be resolved in the direction of the collision or something, but I have no idea really.
I'd like to make it hurt you from falling and when other physics objects bash into you. Running along a floor shouldn't hurt you though.

While I've posted this, any ideas why, when the display is rotated, and you click, the effect isnt at the mouse. (It sets position to mousex("Main") mousey("Main"), seems to bug out when rotated, large possibility I just messed it up though.)

oh and also, may as well ask, how do I timedeltaify the scrolling//rotating events?
B
2
S
2
G
5
Posts: 236
Reputation: 2,122


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests