Jump to content

(Help)How to increase character walk/runspeed?


Recommended Posts

Hi! I have a character that can transform in a different state. I'd like to increase my character's speed during one of the forms.

 

So I tried using inst.components.locomotor.walkspeed but this permanently changes the character's speed, not only after the transformation. I know for a fact that the code was in the right place, because the damage multiplier does work.

 

I simply don't know the right code I need to insert. Some help? :) Oh and do I also need to add a "runspeed"? I guess not because you can only get around at a certain speed as a character, right?

 

Thanks in advance ;)

Link to comment
Share on other sites

That is the correct code, you just don't use it correctly. When the character transforms, you need to set the run/walkspeed again. How you do that depends on how your character knows when to transform (werebeast component, custom component, event listener, etc.)

Link to comment
Share on other sites

@Mobbstar, I thought that I was using it correctly because the damage multiplier does work, and I put the code in the same area. Maybe I need to set some kind of "walkspeed multiplier"? Here's the code I use, it's basicly a rerun of Wolfgang's transformation code. It's quite long, the only code needed to be looked at is the "applymightiness" function and the master_postinit. The applymightiness function gets called by listening for event "sanitydelta" and "newstate" (in the exact same lines as Wolfgang's code).

 

local function applymightiness(inst)local percent = inst.components.hunger:GetPercent()if inst.strength == "mighty" theninst.components.combat.damagemultiplier = 2inst.components.locomotor.walkspeed = 15elseif inst.strength == "wimpy" theninst.components.locomotor.walkspeed = 2inst.components.combat.damagemultiplier = TUNING.WENDY_DAMAGE_MULT*0.75endend-- This initializes for the host onlylocal master_postinit = function(inst)-- choose which sounds this character will playinst.soundsname = "wilson"-- Stats inst.components.health:SetMaxHealth(100)inst.components.hunger:SetMax(150)inst.components.sanity:SetMax(150)inst.components.combat.damagemultiplier = TUNING.WENDY_DAMAGE_MULT*1.5inst.components.locomotor.walkspeed = 5-- Wolfgang Ripoffinst.strength = "normal"    inst._wasnomorph = nilinst.components.sanity.dapperness = TUNING.DAPPERNESS_HUGE    inst.OnLoad = onload    inst.OnNewSpawn = onloadinst:ListenForEvent("killed", onkilledother)end

 

So in this example you can see that the walkspeed is higher in the mighty form, somewhat lower in the normal form and very low in the wimpy form (all for testing purposes). But there's no difference in-game. So why doesn't the game find a change? How to fix this? :/

 

Please tell me if I need to provide more info

 

Does the game need to listen to an event I haven't heard of like "walkspeedchange" or something? ^^'

Link to comment
Share on other sites

@Mobbstar, Very good point, sir! xD

That fixed it, thanks a lot x')...

 

Edit: While I'm at it, how to change the health value? If I try this the same way using inst.components.health:SetMaxHealth(value), it creates a problem. 

 

So I put "inst.components.health:SetMaxHealth(150)" in the mast_postinit, then "inst.components.health:SetMaxHealth(100)" under the mighty code (same place I did for the runspeed) and "inst.components.health:SetMaxHealth(200)" under the wimpy code (values are intentional). Whenever a creature hurts, say in mighty form (100 health) my character, the character takes damage, loses health but in a fraction of a second it gets bumped back up to 100 (same goes for the wimpy form, during normal form my character can actually die). I think this is because of the set value in master_postinit. Do you know a workaround this one? ^^

 

The code in Wolfgang's lua is 

health_max = easing.linear(mighty_percent, TUNING.WOLFGANG_HEALTH_NORMAL, TUNING.WOLFGANG_HEALTH_MIGHTY - TUNING.WOLFGANG_HEALTH_NORMAL, 1) 

which is complete rigmarole to me. How can I simply change the value to any number I'd like? If this is not possible, how does this piece of code work? What's the purpose for the commas here?

Edited by Thibooms
Link to comment
Share on other sites

Increase speed:

inst.components.locomotor:SetExternalSpeedMultiplier(inst, "my_speed_bonus", 1.5) -- Bonus +50%

​Roll back:

inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "my_speed_bonus") -- Will remove bonus

Link to comment
Share on other sites

@Maris, Thank you for the reply. :)

 

 The runspeed is working, don't worry. Although your code is most likely a lot more computable, I'll stick to the hard-coded values I used (because it works and isn't complicated, so I'm not going to bother :p).

 

But what would be more interesting is a way of changing the maximum and current health of the character, depending on the mightyness. I'd do it the same way Wolfgang does, but I don't really understand how easing.linear works. An easy fix for this would really be awesome, or if you could link me something to help me understand that particular code I'd be alright as well :)

Link to comment
Share on other sites

The runspeed is working, don't worry.

 

question about compatibility with other mods ;)

 

 

 

but I don't really understand how easing.linear works

So look at easing.lua in game's scripts folder.

​Here it is - https://github.com/EmmanuelOga/easing/blob/master/lib/easing.lua 

local function linear(t, b, c, d)	 return c * t / d + bend

 

Btw google and/or serch in files helps a lot with these simple things ;)

Edited by Maris
Link to comment
Share on other sites

@Maris, I don't see how this would interfeer with another mod. It only affects the character prefab, right? :).

 

Btw google and/or serch in files helps a lot with these simple things

 

Sure, thing is I did Google it ^^'. But I didn't spend a lot of time in the game files, that's true (I found some code related to it but that didn't explain it). Thanks, I got everything on this topic now :p 

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
 Share

×
  • Create New...