Explode (piece) that can be given a direction/speed
Posted: 07 Dec 2011, 21:23
Usually Explode (piece) makes the piece fly of in some lame random direction.
From
void CUnitScript::Explode(int piece, int flags)
0.5f-gs->randFloat()) * 6.0f, 1.2f + gs->randFloat() * 5.0f, (0.5f - gs->randFloat()) * 6.0f
But the speed of the unit is also factored in and thus if you change unitspeed via MoveCtrl, you can basically direct what speed/direction the pieces fly:


Problem is, changing unit speed makes it go into that direction because physics. So atm I only got it to work with unmobile units, but eg for death animations it should be ok with mobile units. (dead units dont move unless journeywar)
Also works with SHATTER btw, the shards fly off in the same direction.
From
void CUnitScript::Explode(int piece, int flags)
0.5f-gs->randFloat()) * 6.0f, 1.2f + gs->randFloat() * 5.0f, (0.5f - gs->randFloat()) * 6.0f
But the speed of the unit is also factored in and thus if you change unitspeed via MoveCtrl, you can basically direct what speed/direction the pieces fly:


Code: Select all
function headExplodeTest ()
local speed = 100
local x,y,z=Spring.GetUnitPosition (unitID) --needed so unit does not bounce all over the place
while (true) do
for a = 1, 360, 10 do
xs = math.sin (math.rad(a)) * speed
zs = math.cos (math.rad(a)) * speed
Spring.MoveCtrl.Enable (unitID)
Spring.MoveCtrl.SetPhysics (unitID, x,y,z,
xs, 0, zs,
0, 0, 0)
Explode (head, SFX.FALL)
--Spring.MoveCtrl.Disable (unitID) --doesnt seem to work
Sleep (100)
end
end
end
Also works with SHATTER btw, the shards fly off in the same direction.