projectile that splits into multiple booms

projectile that splits into multiple booms

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

projectile that splits into multiple booms

Post by knorke »

This is how you one can make a weapon that splits into multiple bombs.
Image

The idea is like this:
-give tank a "target marker" weapon
-detect impact of "target marker"
-create aircraft unit at tank's position: this is the real projectile
-projectile unit gets attack order to impact position of "target marker"
-projectile unit attacks that spot, then kills itself

The "target marker weapon" is needed because afaik there is no real other way to tell where a unit will/has shot.
(Make this fake weapon "super fast flying" and invisible if you want)

Only the relevant parts:

gagdget:

Code: Select all

local clusterWeapon = {}
clusterWeapon[WeaponDefNames["tplaunchbox_targetmarker"].id] = true
--if weapondef is defined in unitdef, its name is like   unitname+"_"+weaponname
function gadget:Initialize()
	for v,k in pairs (clusterWeapon) do	
		Script.SetWatchWeapon (v, true)
	end
end

--this callin is only called for weapons that have it enabled with Script.SetWatchWeapon
--(which is done in the above lines)
 function gadget:Explosion(weaponID, px, py, pz, ownerID)
	if (clusterWeapon [weaponID]) then
		env = Spring.UnitScript.GetScriptEnv(ownerID)
		if (env) then Spring.UnitScript.CallAsUnit(ownerID, env.launchMissile, px, py, pz) end	
	end
	return true
 end
unit script:

Code: Select all

function launchMissile (targetX,targetY,targetY)
		local x,y,z = Spring.GetUnitPiecePosDir (unitID, flare)
		local missile = Spring.CreateUnit ("tpcruisemissile", x,y,z, math.random(1,4), teamID)
		Spring.SetUnitNoSelect (missile, true)
		Spring.GiveOrderToUnit(missile, CMD.FIRE_STATE , { 0 }, {}) --hold fire
		Spring.GiveOrderToUnit(missile, CMD.ATTACK  , {targetX,targetY,targetY}, {CMD.OPT_INTERNAL}) 
end
+ the usual aimweapon() etc stuff to fire the fake weapon

Notice Spring.GetUnitPiecePosDir instead of GetUnitPosition so that the projectile appears at gun of unit, instead of at its feet.

unit script of projectile, to make it kill itself after shooting:

Code: Select all

local shots = 0
function script.FireWeapon()
	shots=shots +1
	if shots > 5 then Spring.DestroyUnit (unitID) end
	--EmitSfx(flare, muzzleflash)	
end
unitdef for projectile unit:
I found gunships with somewhat quick speed,turnrate etc work best.
Aircraft give nicer flight paths but sometimes fly in stupid circles.
With target categories, you can also make the projecitile attackable.
(think scud & tomahawk missiles in C&C Generals)
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: projectile that splits into multiple booms

Post by gajop »

i wanna see you antinuke this MIRV!
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: projectile that splits into multiple booms

Post by KDR_11k »

Yeah, I've dealt with that in the KP signal nuke and the THIS torpedoes. Neither of them actually deploy multiple warheads but both are unit-typed weapons, the signal mostly for kicks and the torps so that point defense can shoot them down.
Post Reply

Return to “Game Development”