Jump to content

[Solved] Character speed scaling doesn't work

Recommended Posts


I have a little bit of trouble with my character speed scaling.

I use the following coding, but it doesn't seem to work:



local function fastestevil(inst)
local currenthealth = inst.components.health.currenthealth

if inst:HasTag("playerghost") then return end
if inst.components.health:IsDead() then return end

    -- stage I
    if currenthealth <= 150 then
        inst.components.locomotor.walkspeed = 4
    -- stage II
    if currenthealth >= 151 and currenthealth <= 350 then
        inst.components.locomotor.walkspeed = 2.5
    -- stage III
    if currenthealth >= 351 and currenthealth <= 500 then 
        inst.components.locomotor.walkspeed = 1
    -- stage IV
    if currenthealth >= 501 then
        inst.components.locomotor.walkspeed = 0.5

In local master_postinit = function(inst):

    inst:DoPeriodicTask( 0.0, function(inst)


The speed of my character doesn't change at all. What did I missed?

Noteable: I also use a "inst.Transform:SetScale()" local function for the same Health values.

Edited by BillTheCipher
Link to comment
Share on other sites

local function HungerChange (inst)
if inst:HasTag("playerghost") then--basic need
local hunger = inst.components.hunger:GetPercent() > .35 and inst.components.hunger:GetPercent() or .35
local scale = (2.05 * hunger)--gonna have this on config later
local damage = hunger > .4 and hunger or .4
local speed = inst.components.hunger:GetPercent() > .8 and .8 or 1

inst.Transform:SetScale(scale*1.3, scale, scale)
inst.components.combat.damagemultiplier = damage
inst.components.locomotor:SetExternalSpeedMultiplier(inst, "chungus_speed", speed )

I think that the speed in minimal when the size is so huge so i'd use :SetExternalSpeedMultiplyer

i'm not sure how to explain this so i'll leave the way i did it here

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...