Character speed updated in Lua

  • #1, by darren-beckettFriday, 13. May 2016, 13:54 4 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
    1
    2
    3
    4
    5

    Great Poster

    351 Posts


  • #2, by afrlmeFriday, 13. May 2016, 14:14 4 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".

    Imperator

    6846 Posts

  • #3, by darren-beckettFriday, 13. May 2016, 14:33 4 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?

    Great Poster

    351 Posts

  • #4, by darren-beckettFriday, 13. May 2016, 14:39 4 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.

    Great Poster

    351 Posts

  • #5, by afrlmeFriday, 13. May 2016, 15:22 4 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
    1
    2
    3
    4
    5
    6


    I would recommend writing a function instead so you can access it much easier.

    Imperator

    6846 Posts

  • #6, by darren-beckettFriday, 13. May 2016, 15:28 4 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.

    Great Poster

    351 Posts

  • #7, by darren-beckettFriday, 13. May 2016, 15:33 4 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.

    Great Poster

    351 Posts

  • #8, by afrlmeFriday, 13. May 2016, 15:33 4 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.

    Imperator

    6846 Posts

Write post