License from €75
DE EN FR ES IT CZ

Character speed updated in Lua

This thread is a few years old. Some details may refer to an earlier version of Visionaire Studio. Current tutorials

  1. · 11 years ago
    Hi All,

    Is there a way to update the character speed dynamically using Lua?

    This does not work:
    local speed = 300
    local charOutfit = getObject("Characters[CharName]"):getLink(VCharacterCurrentOutfit)
    print("Outfit Speed = ", charOutfit.OutfitCharacterSpeed)  -- This prints correctly
    charOutfit.OutfitCharacterSpeed = speed  -- This has no affect
    

  2. Working on a game?

    The free version covers up to 25 scenes per project. For more scenes and to sell your game, you need a license.

    See licenses Try it for free
  3. · 11 years ago
    I think it depends on the walk type you have specified in the outfits properties tab. The default sliding option should allow you to increase the characters walk speed. However I recommend duplicating the characters walk animations, increasing the movement values in them & then toggling between character animation index values as needed. Double click > change character animation index to 1, wait until character stops, change character animation index value to 0.

    I'm not sure if it will work as I've not tested adding character running in the game I'm working on. Instead I've opted for teleporting the character to scene objects when they double click on them & automatically triggering the default command action for them, which in my case is "left_click".
  4. · 11 years ago
    I've found the problem, this is the wrong variable!

    It seems that the OutfitCharacterSpeed always reverts back to 100 after being set (No idea what this is used for).

    I actually need to update the WalkingSpeed value, where is this value?

  5. · 11 years ago
    By the way, i've got running character outfits, I've done it by changing the outfit to a running outfit when required and reverting back to the walk outfit when the character stops moving.
    I've also got a chasing character that will run to catch you up if you are too far away. It works well.
  6. · 11 years ago
    OutfitCharacterSpeed is the correct variable, it's just it doesn't seem to work as it used to do since 4.x - probably because the walk system was changed to allow you to specify if character should slide between positions or update position on each frame.

    Switching between outfits or character animation index values is actually a better method to use anyway. It allows you to use different animations for each which is nice if you want to use an animation that actually looks like the character is running / jogging as opposed to simply playing a super charged version of the walk animation.

    Instead of the OutfitSpeed, you could try adjusting the pause value of the walk animation. I don't know if it will work though.
    local t = {"walk_e", "walk_se", "walk_s", "walk_sw", "walk_w", "walk_nw", "walk_n", "walk_ne"}
    
    for i = 1, #t do
     game.CurrentCharacter.CurrentOutfit.OutfitCharacterAnimations[i].AnimationPause = 40
    end
    


    I would recommend writing a function instead so you can access it much easier.
  7. · 11 years ago
    An outfit change wouldn't be ideal, because my character is a vehicle, of which i'm accelerating and braking.
    So i'd need a load of different outfits which are all the same except for different speeds.
  8. · 11 years ago
    I think i'll setup a load of actions that change the character to different speeds, i could then call the action corresponding to the speed i need.
  9. · 11 years ago
    Try adjusting the global pause value as I mentioned in the second half of my last message. You could probably even increment / decrement the value as needed too, to simulate acceleration & coasting.

This thread is closed because nobody has replied for more than a year. Feel free to ask your question in a new thread.

New thread

Really delete this post?