I'm trying to do multiple things that involve creating many new dynamic rigid bodies objects in realtime.
One of them is a weapon that fires out a burst of particles in all directions.
Another is throwing out pickups and debri using physx so that the pickups and debri collide with objects and whatnot.
The problem is that even the PHY MAKE RIGID BODY DYNAMIC SPHERE is too slow to allow this. I would go and clone or instance the existing collision data. Compute it ONCE and then use the same data every time. However, that's not exactly possible.
You see, you have two options.
1: Have DarkPhysics generate the rigid body's data on every instance
2: Load a collision mesh from harddisk and use that instead
The problem with this is that neither option allows you to take an existing collision mesh and apply it. Why is that?
The only way I can see making this work without framerate drops every time something explodes or a burst weapon is used is to generate a bunch of these objects in the start and hie them until they're needed. However, that's too much of a hack and I'd really rather avoid doing it because to be honest, the game I'm making is essentially a sandbox with an unknown number of maximum "particles" that can pop out.
(edit)
Is there any better way of doing this? Seriously, I realize that too much physics is a bad thing, but spawning merely 12 objects isn't exactly heavy and my system isn't exactly slow. If my monster machine craps out for a quarter of a second, anyone's machine will.
Here's the code I'm using just so you can see how tight the code is:
tpy = numburst `tpy is declared as a float, numburst isn't, need moar typecasting functions!
for i = 1 to numburst
tpx = i
aimangle = tpx * (360.0 / tpy)
posxB = cos(aimangle)
posyB = sin(aimangle)
btAddParticle(3, _tactor, posxA + (posxB), posyA + (posyB), 0, posxB, posyB, 0)
next i
the function, btAddParticle is:
function btAddParticle(bullettype as dword, parent as dword, posx as float, posy as float, posz as float, vecx as float, vecy as float, vecz as float)
partindex as dword
newobj as dword : newobj = btGetFreeObj()
array insert at bottom particle(0)
partindex = array count(particle(0))
instance object newobj, bullet(bullettype).obj
show object newobj
particle(partindex).obj = newobj
particle(partindex).bullet = bullettype
particle(partindex).angx = vecx
particle(partindex).angy = vecy
particle(partindex).angz = vecz
particle(partindex).birth = gtime
particle(partindex).speed = bullet(bullettype).speed
particle(partindex).lifespan = bullet(bullettype).lifespan
particle(partindex).maxcollisions = bullet(bullettype).maxcollisions
particle(partindex).collisions = 0
particle(partindex).collidetogetxp = bullet(bullettype).collidetogetxp
particle(partindex).damp = bullet(bullettype).damp
if bullet(bullettype).sound then btTriggerSound(bullet(bullettype).sound)
position object newobj, posx, posy, posz
phy make rigid body dynamic sphere newobj
phy set rigid body linear velocity newobj, vecx * particle(partindex).speed, vecy * particle(partindex).speed, vecz * particle(partindex).speed
phy set rigid body linear damping newobj, particle(partindex).damp
phy set rigid body angular damping newobj, particle(partindex).damp
endfunction
Everything I needed to know about trigonometry, I learned by becoming a game programmer.