Simulation of the blast wave?

I spent a lot of time on that to make a blast wave with decreasing damage … None of which did not work out. :sob:

Does anyone have any ideas?

Do you mean decreasing damage by distance?
What is not working out? The formula to calculate the damage?
Is the wave circular?

Yes wave is the ball, as have a blast

all that you have written

so given the max radius of the sphere r where the damage will be zero, and given the max damage at distance zero D, you could calculate the damage based on a distance from the center d in a linear way:

// max wave radius
var r = 10;
// max damage
var D = 100;
// current distance from the center
var d = 1;
// clamp the distance between 0 and r
d = Math.min(Math.max(0, d), r);
// distance normalized [0, 1]
var t = d / r;
// final damage
var damage = D - t * D;

if you prefer a not linear damage you could convert t using one of the easing functions here:

for example:

var t = d / r;
t = easeInQuad(t);
1 Like

:scream_cat: :scream:

Can you make simple example? I’m very bad at math… :crazy_face:

I would be very grateful :blush:

I posted a full working code.
The only thing you need to do is to set the correct values of r, D and d.
And you will get the final damage.
Let me know what else you need more in details. What you can’t calculate?

then how is the calculation I seem to understand. I did not understand how to transfer this damage to a physical object. (Collision, rigbody)

But in any case, thank you! :wink:

I see, so you are speaking about forces, not just damage.
In any case, you can now take the “damage” calculated from the previous code, and use it to calculate a force vector.
I’m still new to PlayCanvas and I didn’t study the physics API yet, but in theory you need:

  1. the center of the sphere: c
  2. the position of the object that is hit: p

then you can calculate the force vector as:
f = (p - c) * damage
and use the PlayCanvas API to apply an instant force to your object.

1 Like