Explosion Forces (repelling)
Blitz3D Forums/Blitz3D Programming/Explosion Forces (repelling)
| ||
Anyone have any suggestions on the best method for appling explosion forces.. Ive already gotten the velocity mechanics in there in the most simple form possible = velocityx (vx),velocityy(vy),velocityz(vz), velocity_Decay(vd) , and gravtiy(g). Im wondering how best to assign vx,vy,and vz from a point in 3D space (explosion). giving a Power and Radius of that explosion. so that the closer you are to the blast the more force is applied. I dont want to use a physics lib for somthing so simple, but I want accurace velocity values to pass on to the entity. I usually end up getting these things to work , but I can generaly assume theres much better ways (and faster) to do it, and I dont want to slow things down on this project. Thanks in advance. |
| ||
Vectors and stuff maybe hehe.. http://en.wikipedia.org/wiki/Vector_space Find the normals and somehow do something with them... I haven't figured it all out but... I'm trying. |
| ||
somthing that works if you are facing the explosion. but if you are not facing it, then it pulls instead of repels. what am i missingIf distance(EntityX(t\main),EntityY(t\main),EntityZ(t\main),PickedX(),PickedY(),PickedZ()) < 30 Then ;30 unit range xdist#=EntityX(t\main,1)-PickedX() zdist#=EntityZ(t\main,1)-PickedZ() ydist#=EntityY(t\main,1)-PickedY() dvx#=(.1-(.005 / 100.0)) * xdist ;weird way to calc power dvy#=(5-(.005 / 100.0)) * ydist dvz#=(.1-(.005 / 100.0)) * zdist setentvelocity(t\main,dvx,dvy,dvz) |
| ||
hmm... not sure what kind of physics system you are using... but simply find the dot-product in 3d as follows between the explosion and the object the explosion is repelling.dx# = x1-x2 dy# = y1-y2 dz# = z1-z2 ;dot product in 3d is as follows dot# = dx*dx + dy*dy + dz*dz dist# = Sqr(dot) ;do 1/dotproduct making the explosion dissipate using the inverse square dot# = 1/dot# ;now divide distance vectors by distance and multiply by dot dx# = (dx# / dist#) * dot dy# = (dy# / dist#) * dot dz# = (dz# / dist#) * dot hope you understand the code above. I dont know how to explain it well, it just kinda works for an exponentially dissipating explosion now just apply the vector dx,dy,dz to your physics object ( and redo it for every object in your scene within a resonable range. |
| ||
Thanks alot Nate, I understood it. Wrapped it into a single call . Function ApplyExplosionForce(ent,x2#,y2#,z2#,falloff#=.25) x1=EntityX(ent,1) y1=EntityY(ent,1) z1=EntityZ(ent,1) dx# = x1-x2 dy# = y1-y2 dz# = z1-z2 ;dot product in 3d is as follows dot# = dx*dx + dy*dy + dz*dz dist# = Sqr(dot) ;do 1/dotproduct making the explosion dissipate using the inverse square dot# = 1/dot# ;now divide distance vectors by distance and multiply by dot dx# = (dx# / (dist#*falloff#)) * dot dy# = (dy# / (dist#*falloff#)) * dot dz# = (dz# / (dist#*falloff#)) * dot setentvelocity(ent,dx*2500,dy*2500,dz*2500,999,1) End Function |