Page 1 of 1
Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity
Posted: 01 Apr 2010, 04:37
by shedeki
Following
Jools' request I am trying to write a gadget that spawns a meteor and drops it onto the map. My meteor is a unit (\units\cometunit.lua) that belongs to gaia and is spawned using Spring.CreateUnit. Because that apparently ignored the Y-value I tried Spring.SetUnitPosition to put the meteor up in the sky. Spring.SetUnitVelocity is supposed to give the meteor a push towards to ground:
Code: Select all
local cometID = CreateUnit('cometunit', spawnX, spawnY, spawnZ, "south", gaiaID)
SetUnitPosition(cometID,startX,startY,startZ)
SetUnitVelocity(cometID,velX,velY,velZ)
Spring.CreateUnit and Spring.SetUnitPosition ignore spawnY and startY respectively. Spring.SetUnitVelocity does not seem to do anything. Instead, the meteor just hangs in the air ignoring gravity. The meteors height seems to be the value of CruiseAlt from the UnitDef.
Any ideas as to why the meteor won't move? I thought that this approach should work thinking of all those small units flying around the battlefield following bigger explosions...
This is the first time I'm looking into LUA and also the first time I looked at how a unit is created. Thus, my mistakes might be rather bland...
Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity
Posted: 01 Apr 2010, 06:45
by Argh
Spring.MoveCtrl.Enable(cometID)
Before using those two commands.
Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity
Posted: 01 Apr 2010, 17:37
by shedeki
Thanks a lot, Argh. Lua_MoveCtrl works fine. Spring.MoveCtrl.SetRotationVelocity adds a nice (albeit possibly unrealistic) spin. :)
Right now the meteor passes right through the ground. Can I react to the meteor hitting the ground through LUA and create the explosion manually? Or is there a way to make the meteor receive fall damage, explode and leave a wreckage?
Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity
Posted: 01 Apr 2010, 17:44
by zwzsg
You know the speed the meteor goes at, you know the initial altitude, so the time it hits ground is only a division away. Perform a Spring.DestroyUnit(unitID,true,false) at this time. Or if you are afraid that the ground might get deformed by something else while meteor is travelling, just compare unit y position with ground height at every frame.
Otherwise free falling units most often automatically die from the shock of hitting the ground. But I don't think freefall would work well for meteor showers, since it'd go faster and faster.
Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity
Posted: 01 Apr 2010, 18:45
by FLOZi
Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity
Posted: 03 Apr 2010, 03:54
by shedeki
zwzsg wrote:You know the speed the meteor goes at, you know the initial altitude, so the time it hits ground is only a division away. Perform a Spring.DestroyUnit(unitID,true,false) at this time. Or if you are afraid that the ground might get deformed by something else while meteor is travelling, just compare unit y position with ground height at every frame.
Actually, I was even more worried about the meteor silently passing through steep mountains on its way to its final location, but ground deformation is a big enough issue already.
Checking the units y position against the ground height seems logical but I was afraid that doing the check each frame might get a bit costly. As I don't know anything about how the gadget will influence performance and can't think of a better way, I will do the check though.
zwzsg wrote:Otherwise free falling units most often automatically die from the shock of hitting the ground. But I don't think freefall would work well for meteor showers, since it'd go faster and faster.
Spring.MoveCtrl.SetGravity should solve that problem, I guess. Can't test, as the meteor won't even care about hitting the ground. ;)
I tried
Spring.MoveCtrl.SetCollideStop, but that seems to do something different. At least it does not change the meteors transcendent nature...
Thank you for the help. Substituting my comets with peewees makes the script work already (and a lot of fun to watch :D). I'm guessing that
Spring.DestroyUnit will not work without a COB-file for my comet. Guess I'll have to find out what exactly that is and how I can make one. After that I'll just have to figure out how to work with Explosions, create a wreckage and the whole thing will be done.