SetFeatureRotation and SetFeatureResources don't seem to be working

SetFeatureRotation and SetFeatureResources don't seem to be working

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
Forboding Angel
Evolution RTS Developer
Posts: 14673
Joined: 17 Nov 2005, 02:43

SetFeatureRotation and SetFeatureResources don't seem to be working

Post by Forboding Angel »

Code: Select all

function gadget:GetInfo()
	return {
		name 	= "Death Spawns",
		desc	= "Spawns a Container when a unit dies",
		author	= "",
		date	= "2022",
		license	= "Public domain",
		layer	= 0,
		enabled	= true	--	loaded by default?
	}
end

if gadgetHandler:IsSyncedCode() then

	local partsList = {
		"compressedtanks",
		"laserturret",
		"medtankturret",
		"nanopylon",
		"techdodad",
		"wheels",
	}

	function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
	
		if math.random(1,2) == 1 then
			_, _, _, _, buildProgress = Spring.GetUnitHealth(unitID)
			if buildProgress == 1 then
				local unitName = UnitDefs[unitDefID].name
				local unitCostMetal = UnitDefs[unitDefID].metalCost
				local unitCostEnergy = UnitDefs[unitDefID].energyCost
				posx, posy, posz = Spring.GetUnitPosition(unitID)
				-- Spring.Echo("[Death Spawns] Unit Name is " .. unitName)
				local featureID = Spring.CreateFeature (partsList[math.random(1,#partsList)], posx, posy, posz, 0, unitTeam)
				if featureID then
					-- Spring.Echo("[Death Spawns] Unit Cost is " .. unitCostMetal)
					Spring.SetFeatureResources(featureID, unitCostMetal * 0.25, unitCostEnergy * 0.25)
					Spring.SetFeaturePosition(featureID, posx, posy, posz,  false)
					
					dirx = math.random(1,100000)
					diry = math.random(1,50000)
					dirz = math.random(1,100000)
					Spring.SetFeatureDirection(featureID, dirx, diry , dirz)
					
					rotx = math.random(1,50)
					roty = math.random(1,100)
					rotz = math.random(1,50)
					Spring.SetFeatureRotation(featureID, rotx, roty , rotz)
				end
			end
		end
	end
	
end
So what I'm trying to accomplish is wreckfields littered with parts from units. I wanted those parts to be worth x% of the original unit.

The issues I am having is that setfeatureresources is having no effect whatsoever, even when being set to a specific value.

The other issue is that SetFeatureRotation is having no effect except around the Y axis.

Things I have tried:
Spring.SetFeatureMoveCtrl(featureID,false,1,1,1,1,1,1,1,1,1) and moving everything to movectrl, but this isn't super helpful when it comes to x/z rotations.
I have tried using SetFeaturePhysics to do everything. I don't have those examples, so hopefully just take my word for it.

Does anyone know the secret to getting a feature to rotate around the x/z axis and setting that feature's worth?


Tried another method after that:

Code: Select all

function gadget:GetInfo()
    return {
        name     = "Death Spawns",
        desc    = "Spawns a Container when a unit dies",
        author    = "",
        date    = "2022",
        license    = "Public domain",
        layer    = 0,
        enabled    = true    --    loaded by default?
    }
end

local featuresToRotate = {}

if gadgetHandler:IsSyncedCode() then

    local partsList = {
        "compressedtanks",
        "laserturret",
        "medtankturret",
        "nanopylon",
        "techdodad",
        "wheels",
    }

    function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
    
        if math.random(1,2) == 1 then
            _, _, _, _, buildProgress = Spring.GetUnitHealth(unitID)
            if buildProgress == 1 then
                -- local unitName = UnitDefs[unitDefID].name
                local unitCostMetal = UnitDefs[unitDefID].metalCost
                local unitCostEnergy = UnitDefs[unitDefID].energyCost
                local posx, posy, posz = Spring.GetUnitPosition(unitID)
                -- Spring.Echo("[Death Spawns] Unit Name is " .. unitName)
                local featureID = Spring.CreateFeature (partsList[math.random(1,#partsList)], posx, posy, posz, 0, unitTeam)
                if featureID then
                    featuresToRotate[featureID] = {unitCostMetal,unitCostEnergy}
                end          
            end
        end
    end
    
    function gadget:FeatureCreated(featureID)
        if featuresToRotate[featureID] then
            local unitCostMetal = featuresToRotate[featureID][1]
            local unitCostEnergy = featuresToRotate[featureID][2]
            local posx, posy, posz = Spring.GetFeaturePosition(featureID)

            -- Spring.Echo("[Death Spawns] Unit Cost is " .. unitCostMetal)
            Spring.SetFeatureResources(featureID, unitCostMetal * 0.25, unitCostEnergy * 0.25)
            Spring.SetFeaturePosition(featureID, posx, posy, posz,  false)
            
            dirx = math.random(1,100000)
            diry = math.random(1,50000)
            dirz = math.random(1,100000)
            Spring.SetFeatureDirection(featureID, dirx, diry , dirz)
            
            rotx = math.random(1,50)
            roty = math.random(1,100)
            rotz = math.random(1,50)
            Spring.SetFeatureRotation(featureID, rotx, roty , rotz)
            --Spring.SetFeatureRotation(featureID, math.random()*360, math.random()*360 , math.random()*360)

            featuresToRotate[featureID] = nil
        end
    end 

    
end
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: SetFeatureRotation and SetFeatureResources don't seem to be working

Post by Beherith »

See: https://github.com/beyond-all-reason/Be ... eller.lua

Also note the amount of changes regarding this exact behaviour :D
Post Reply

Return to “Game Development”