Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
shedeki
Posts: 17
Joined: 05 Mar 2007, 13:53

Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Post 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...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Post by Argh »

Spring.MoveCtrl.Enable(cometID)

Before using those two commands.
User avatar
shedeki
Posts: 17
Joined: 05 Mar 2007, 13:53

Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Post 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?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Post 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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Post by FLOZi »

http://springrts.com/wiki/Lua_MoveCtrl

Spring.MoveCtrl.SetCollideStop ?
User avatar
shedeki
Posts: 17
Joined: 05 Mar 2007, 13:53

Re: Unit Control ÔÇô Spring.SetUnitPosition/Spring.SetUnitVelocity

Post 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. ;)
FLOZi wrote:http://springrts.com/wiki/Lua_MoveCtrl

Spring.MoveCtrl.SetCollideStop ?
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.
Post Reply

Return to “Lua Scripts”