Walk speed dependant on current scale

  • #1, by spacepawWednesday, 16. November 2011, 13:49 10 years ago
    Another snippet from me. If you think that it's not ok for the character to move at the same speed when he's "further away" and "close to the camera" feel free to use this script - it multiplies the walk speed by character scale and adds minimum walk speed (so the character actually moves with reasonable speed even when at really small scale like 5%). The one thing I noticed is the lack of CharracterCurrentScale variable (there is scale yes, but it's static). That's why I had to use AnimationSize instead. This created another problem - this value is updated only when the animation is actually played so the script needs to check for current walk animation - that's why it's so long and dependant on animation names. If anyone knows how to simplify it please post solution here.

    Just remember to switch Hero to your character id, HeroWalkX animation names to your walk animations ids and MainHeroOutfit to your character outfit id. Also depending on your resolution tweak minSpeed and fullWalkSpeed variables.

    Also I wrote 360-23 etc. instead of 337 because it's more obvious what it means smile feel free to change that as well.

    fullWalkSpeed = 300minSpeed = 100function OnMainLoop()	if( getObject( "Characters[Hero]" ):getInt( VCharacterState )==3 ) then		local direction = getObject("Characters[Hero]"):getInt(VCharacterDirection)		if( direction > 360-23 or direction < 23 ) then			weight = getObject("ActiveAnimations[HeroWalkE]"):getInt(VAnimationSize)		elseif( direction > 315-23) then			weight = getObject("ActiveAnimations[HeroWalkSE]"):getInt(VAnimationSize)		elseif( direction > 270-23) then			weight = getObject("ActiveAnimations[HeroWalkS]"):getInt(VAnimationSize)		elseif( direction > 225-23) then			weight = getObject("ActiveAnimations[HeroWalkSW]"):getInt(VAnimationSize)		elseif( direction > 180-23) then			weight = getObject("ActiveAnimations[HeroWalkW]"):getInt(VAnimationSize)		elseif( direction > 135-23) then			weight = getObject("ActiveAnimations[HeroWalkNW]"):getInt(VAnimationSize)		elseif( direction > 90-23) then			weight = getObject("ActiveAnimations[HeroWalkN]"):getInt(VAnimationSize)		elseif( direction > 45-23) then			weight = getObject("ActiveAnimations[HeroWalkNE]"):getInt(VAnimationSize)		end		weight=weight/100.0		getObject("Outfits[MainHeroOutfit]"):setValue(VOutfitCharacterSpeed,weight*fullWalkSpeed+minSpeed)	endendregisterEventHandler("mainLoop", "OnMainLoop")
    1

    Newbie

    0 Posts


  • #2, by afrlmeThursday, 18. April 2013, 18:15 9 years ago
    "VCharacterSize" will be available in the next release of Visionaire Studio which allows you to call the characters current scale size (read only)

    -- let's create some initial variables
    local minSpeed = 120 -- min speed value
    local maxSpeed = 350 -- approx normal walking speed value
    local initialTime = getTime() -- store the initial time of the timer
    local targetTime = 500 -- set target time in ms (to prevent setWalkSpeed from being called 100's of times in under a second)

    -- let's create the function in which we set the walk speed of the current character
    function setWalkSpeed()
    tblWalk = {}
    tblWalk["_temporary_"] = ""
    tblWalk[1] = game:getLink(VGameCurrentCharacter) -- store current character
    tblWalk[2] = tblWalk[1]:getInt(VCharacterSize) / 100 -- store current character scale & divide by "100"
    tblWalk[3] = tblWalk[1]:getLink(VCharacterCurrentOutfit) -- store current character outfit
    tblWalk[4] = tblWalk[3]:getInt(VOutfitCharacterSpeed) -- store current outfit speed
    tblWalk[5] = tblWalk[2] * maxSpeed + minSpeed -- calculate the new walk speed
    -- * break * --
    if tblWalk[5] > maxSpeed then tblWalk[5] = maxSpeed end -- check if walk speed is more than max speed
    if tblWalk[4] ~= tblWalk[5] then tblWalk[3]:setValue(VOutfitCharacterSpeed, tblWalk[5] ) end -- set the new walk speed
    end

    -- let's create the onMainLoop function in which we store functions we want to loop
    function onMainLoop()
    if (game:getLink(VGameCurrentCharacter):getInt(VCharacterState) == 3) and (getTime() >= initialTime + targetTime) then -- is character walking & has the timer elapsed a specific time?
    getTime({flags=1, reset=true}) -- reset the timer back to 0
    setWalkSpeed() -- call walk speed function
    end
    end

    -- let's create the mainLoop handler
    registerEventHandler("mainLoop", "onMainLoop")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31


    * edit: fixed!

    here's what happens without delaying the mainLoop function.
    02:50:23: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:24: the mainLoop handler loops rapidly
    02:50:25: the mainLoop handler loops rapidly
    02:50:25: the mainLoop handler loops rapidly
    02:50:25: the mainLoop handler loops rapidly
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34

    as you can see - it's not very nice & I doubt it helps much.

    I'm using the current eventHandler system at the minute as I'm waiting until Dundil finishes his custom eventHandler/Listener & delay function scripts.

    getTime() is more of a developers tool for checking time taken to execute/do something between point a & point b, whereas I've used it as a crude delay function. the problem is we can only use the one getTime() function & we can only check the time or reset it back to 0.


    * another edit: yes another! - I am not actually using this script like this for the footstep functions script I am working on - instead I am calling the footstep function on each foot contact with the ground in the same way I am controlling the footstep volume & audio balance .. snippet of code I'm using for walk speed below
    -- * begin walk speed code * --

    -- let's create some initial variables
    local minSpeed = 120 -- min speed value
    local maxSpeed = 350 -- approx normal walking speed value

    -- let's create the function in which we set the walk speed of the current character
    function setWalkSpeed()
    tblWalk = {} -- empty table
    tblWalk["_temporary_"] = "" -- set as temporary table
    tblWalk[1] = game:getLink(VGameCurrentCharacter) -- store current character
    tblWalk[2] = tblWalk[1]:getInt(VCharacterSize) / 100 -- store current character scale & divide by "100"
    tblWalk[3] = tblWalk[1]:getLink(VCharacterCurrentOutfit) -- store current character outfit
    tblWalk[4] = tblWalk[3]:getInt(VOutfitCharacterSpeed) -- store current outfit speed
    tblWalk[5] = tblWalk[2] * maxSpeed + minSpeed -- calculate the new walk speed
    -- * break * --
    if tblWalk[5] > maxSpeed then tblWalk[5] = maxSpeed end -- check if walk speed is more than max speed
    if tblWalk[4] ~= tblWalk[5] then tblWalk[3]:setValue(VOutfitCharacterSpeed, tblWalk[5] ) end -- set the new walk speed (only if new speed is not same as current speed value)
    end

    -- * end walk speed code * --
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22

    for me the function is less complicated & is called only when needed smile

    Imperator

    7005 Posts

  • #3, by doroboThursday, 14. April 2016, 22:59 5 years ago
    Im new here and i just drawing my game for now. Spent little time in visionaire free version. I have these long perspectives in some scenes. I hoped i could increase/decrease movement speed with waypoints somehow. Is this method the only way? And will it work in current version?Thanks.

    Newbie

    46 Posts

  • #4, by afrlmeFriday, 15. April 2016, 00:10 5 years ago
    To be honest I have no idea. Both of the scripts are super old & Visionaire Studio has been overhauled since then.

    I believe walk speed is supposed to be dependent automatically based on your active characters current scale, but I could be wrong. If not it would be easy enough to create a small loop & function that adjusts the current walk speed based on the scale of the character - probably with a few lines of code now instead of a massive script as we now have refined shorthand variations for accessing & editing pretty all of the visionaire objects via Lua script. wink

    It's too late for me to attempt trying to type up a script off the top of my head as math makes my brain hurt.

    Imperator

    7005 Posts