Hi Walaber, glad to see you've seen the post about Newton stuff. I have this code here from the fps bullet collision module. It's inside a loop that loops through the projectiles, there's nothing wrong with that, it's just that the intersections are detected when I shoot into weird places. It's almost like the world has shrunk into one corner, although the debug model shows that the objects are where they should be. Is there any special stuff I have to do for the raycasts to work. I have included mesh and memblock commands in my program. G_Projectile().pos and .vel are correct, I can see that from the tracers. G_LoopSpeed is just a loop time scalar. Cheers.
NDB_SetVector 1,G_Projectile(x).pos.x,G_Projectile(x).pos.y,G_Projectile(x).pos.z
NDB_SetVector 2,G_Projectile(x).pos.x+G_Projectile(x).vel.x*G_LoopSpeed,G_Projectile(x).pos.y+G_Projectile(x).vel.y*G_LoopSpeed,G_Projectile(x).pos.z+G_Projectile(x).vel.z*G_LoopSpeed
intersect = NDB_NewtonWorldRayCast()
if intersect < 1.0
body = NDB_RayCastGetBody()
if body <> 1 then message "Body "+str$(body)
pos.x = G_Projectile(x).pos.x + NDB_RayCastGetDist()*G_Projectile(x).vel.x*G_LoopSpeed
pos.y = G_Projectile(x).pos.y + NDB_RayCastGetDist()*G_Projectile(x).vel.y*G_LoopSpeed
pos.z = G_Projectile(x).pos.z + NDB_RayCastGetDist()*G_Projectile(x).vel.z*G_LoopSpeed
NDB_RayCastGetNormal
norm.x = NDB_GetVector_X()
norm.y = NDB_GetVector_Y()
norm.z = NDB_GetVector_Z()
if NDB_NewtonBodyGetMassMatrix(body) > 0.0
NDB_SetVector 1, norm.x, norm.y, norm.z
NDB_SetVector 2, pos.x, pos.y, pos.z
NDB_NewtonAddBodyImpulse body
NDB_NewtonWorldUnfreezeBody body
endif
G_Projectile(x).pos.x = pos.x
G_Projectile(x).pos.y = pos.y
G_Projectile(x).pos.z = pos.z
G_Projectile(x).exist = 0
endif
if G_Projectile(x).exist
inc G_Projectile(x).pos.x,G_Projectile(x).vel.x*G_LoopSpeed
inc G_Projectile(x).pos.y,G_Projectile(x).vel.y*G_LoopSpeed
inc G_Projectile(x).pos.z,G_Projectile(x).vel.z*G_LoopSpeed
inc G_Projectile(x).rot.z,10.0 * G_LoopSpeed
endif
Edit, it's not as if it has shrunk into one corner actually, it is only detecting intersections with certain objects, when you test from a certain angle. But it is detecting the collisions in the right place when it does.
EDIT AGAIN!!!
Problem solved! Forgot to increase the world size
. Stupid me, I'm now shooting barrels and crates around nicely
.
Isn't it? Wasn't it? Marvellous!