#### SirLagsalott

##### Member

Code:

```
if abs(phy_linear_velocity_x) + abs(phy_linear_velocity_y) > 50 then {
woodhealth = woodhealth - ((abs(phy_linear_velocity_x) + abs(phy_linear_velocity_y))/32)
}
```

- Thread starter SirLagsalott
- Start date

Code:

```
if abs(phy_linear_velocity_x) + abs(phy_linear_velocity_y) > 50 then {
woodhealth = woodhealth - ((abs(phy_linear_velocity_x) + abs(phy_linear_velocity_y))/32)
}
```

Thank you. Didn't know it'd be that easy.

First of all you need to know that at the time of the collision event, the speed have already been altered by the collision.

Therefore you must have a couple of variables keep track of what the speed vector was previous to the collision. I think you can do that by setting the variables equal to phy_speed_x and phy_speed_y in the end step event. I'm not totally sure when collision events fire, so you might want to look into that if you want totally accurate results. Becuase accelerations that happened during this step might not have applied yet if the collision event fires first.

Anyway, to get the force of the collision, all you need to know is what your change in velocity was. And you can get that by measuring the distance between your previous velocity vector and your vector after the collision. And you should also take into account the mass of the instance that has been moved by the collision, becuase it will take more force to change a more massive object the same speed over the same length of time.

var _force = point_distance(old_speed_x, old_speed_y, phy_speed_x, phy_speed_y) * phy_mass;

If I'm not mistaken, the collision event for physics objects fires every iteration of the physics world, so if physics world iterations are set to 60, then the collision event fires 60 timesI'm not totally sure when collision events fire, so you might want to look into that if you want totally accurate results. Becuase accelerations that happened during this step might not have applied yet if the collision event fires first.

P

No, this wont work if the object is spinning. Imagine a fast-spinning top hitting another top, making a big change to angular momentum. The impulse might be very high, but the change in linear velocity would be very low.

First of all you need to know that at the time of the collision event, the speed have already been altered by the collision.

Therefore you must have a couple of variables keep track of what the speed vector was previous to the collision. I think you can do that by setting the variables equal to phy_speed_x and phy_speed_y in the end step event. I'm not totally sure when collision events fire, so you might want to look into that if you want totally accurate results. Becuase accelerations that happened during this step might not have applied yet if the collision event fires first.

Anyway, to get the force of the collision, all you need to know is what your change in velocity was. And you can get that by measuring the distance between your previous velocity vector and your vector after the collision. And you should also take into account the mass of the instance that has been moved by the collision, becuase it will take more force to change a more massive object the same speed over the same length of time.

var _force = point_distance(old_speed_x, old_speed_y, phy_speed_x, phy_speed_y) * phy_mass;

I wish there was a way of determining the magnitude of the collision impulse, but all we get is a unit vector. Would it be so hard to also supply the impulse vector for the collision?

Are you sure? According to what I read, and the tests that I'm doing, the change in linear velocity is always the same when the same magnitude of force is applied, no matter where it is applied. Is there something different about collisions that would change that?