Jump to content

How do I make a character's speed change depending on their equipment?


CathMario

Recommended Posts

 have a event listener in your character file, with a function. then check what you just equipped, if its a hat/armor then change the character speed.

Example:

Function OnEquip(inst) -- the inst is our character
	local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HEAD) --or local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY)
	if item:HasTag("speedup") then --for this either make the hats you want have the tag either speedup or speeddown
    	inst.components.locomotor.walkspeed = 6
		inst.components.locomotor.runspeed = 8
    elseif item:HasTag("speeddown") then
    	inst.components.locomotor.walkspeed = 2
		inst.components.locomotor.runspeed = 4
    end
  --also you can make it so it lowers your character health or max health
end

local fn = function(inst) -- your character code
	inst:ListenForEvent("equip", OnEquip)
end

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...