I've been messing around with this raycasting idea, the for-next loop throught bodies works fine, I get reaction to every body when the grenade explodes, but I'm missing the key thing, I somehow can't get Newton to return when there is objects intersecting the explosion...
Here is my raycasting, mostly ripped from Newton examples because I'm still learning this, I haven't really done any calculations myself so the exploding force is blowing the objects to the same direction regardless the grenade position.
I should be able to figure those out, but does anyone know why my raycast (for testing I got known certain body number) is returning anything around 0.85 to 0.95 regardless if there is static object(mass 0) intersecting or not.
And when I throw the grenade really far from the object it returns 1.1...
I thought it might be because the grenade and the object are lying on ground, the ray might intersect the floor before reaching the object, but that is not the case because same happens if I throw the grenade in the air and it explodes there with clear line to the object.
tx1# = object position x(ObjM67) : ty1# = object position y(ObjM67) : tz1# = object position z(ObjM67)
for a=1 to NDB_DebugRigidBodyCount()
if NDB_BodyExist(a)=1
NDB_BodyGetPosition a
tx2# = NDB_GetVector_X()
ty2# = NDB_GetVector_Y()
tz2# = NDB_GetVector_Z()
dx# = tx2# - tx1#
dy# = ty2# - ty1#
dz# = tz2# - tz1#
NDB_SetVector 1, tx1#, ty1#, tz1#
NDB_SetVector 2, tx2#, ty2#, tz2#
dist# = NDB_NewtonWorldRayCast()`bodies with mass >0.
if dist# < 1.0
HitBody = NDB_RayCastGetBody()
castdist# = dist# * 50
cast_x# = tx1# + (dx# * castdist#)
cast_y# = ty1# + (dy# * castdist#)
cast_z# = tz1# + (dz# * castdist#)
hitmass# = NDB_NewtonBodyGetMassMatrix( HitBody )
if hitmass# > 0.0
NDB_SetVector 1, cast_x#, cast_y#, cast_z#
NDB_SetVector 2, dx#*20, dy#*20, dz#*20
NDB_BodyAddForceGlobal HitBody
NDB_NewtonWorldUnfreezeBody HitBody
endif
endif
endif
next a
return