[Mod Request] Floor type affects movement speed

Talk about the mods you'd like to see in Daggerfall Unity. Give mod creators some ideas!
User avatar
haloterm
Posts: 391
Joined: Sat Feb 16, 2019 5:21 am

[Mod Request] Floor type affects movement speed

Post by haloterm »

We have snow currently in our city in Germany, which is quite rare in the recent years.

While going for a walk, it occured to me that moving through high snow is quite similar to walking through sand on a beach.

And then I noticed that in many 1st person computer games, movement speed is usually never influenced by the ground (except when swimming in water). I think when we walk through snow or desert sands, the player (and in fact also most enemies if they are not esp. fit to the environment) should get a small malus on their speed, so it's a noticable difference. Walking on roads (as added by Basic Roads) should give no malus.

Would such thing be possible in DFU? (Or could it be added to "Climates & Calories" mod maybe?)

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: [Mod Request] Floor type affects movement speed

Post by BadLuckBurt »

It's technically possible, you can check the climate a player is in at any time (for determining desert, swamp etc.) and you can also check what kind of tile is beneath the player.

I suppose checking every x frame wether the surface / climate has changed and adjusting the speed should be more than enough. I'm not sure if the player speed can be freely modified but making that possible would be rather easy.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by l3lessed »

Burt, don't begin working on this, if you haven't.

I went at it today. I already have a switch system setup for movement modifying; Tying it to terrain type, not only attack state, is critical to improving the feel of combat in my opinion, so I need to hammer it out anyways for my combat modding.

There is an override bool switches for run and walk speeds, and if used correctly, you can use them to override default movement speeds. You just have to be clever about using the movement speed and bool switch together to turn it on and off without causing it to get stuck and bug players movement speed. Will see if running two mods using this method causes any bugs, but it works great right now on the one mod I use it in.

As for now, the plan for this mod is to reconstruct my weapon properties text reader for tiles, which I just finished. It will now read the text file, look for any line with a assigned tile id, and then update the players speeds based on the value put into the text file.

I'm going to text file use because of the amount of differing tiles makes it hard to hardcode in all the id's and still allow player customization. I won't load up the settings area with endless individual tile id value either; jus feels clunky. Also, removing it from the hardcode and moving it into a text file to store the ids and linked movement modifier values allows for the addition of both custom tiles from modders and future tile changes/additions from developers. If an ID is not found, it will default movement speed back to original value by turning the modifier back to 1x.

At this point, I merely need to reconstruct the movement code I use in my other mod to change player movement on the fly and then link it to the text properties being pulled.

The last step is then to get myself and everyone to begin adding all the tiles and custom values, so we can get more nuanced movement changes. When I hook up the movement code to the text reader, I'll drop it as a dev release for a week or so to let people play with ID's and movement numbers.

I'm going to keep it a general movement modifier and not split the values based on running or walking. If you reduce movement by 50%(.5), it will do the same for both run and walk. Technically, they can be separated and walk and run given their own movement values, but this seems unneeded to me.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by Hazelnut »

l3lessed wrote: Thu Feb 18, 2021 8:39 pm There is an override bool switches for run and walk speeds, and if used correctly, you can use them to override default movement speeds. You just have to be clever about using the movement speed and bool switch together to turn it on and off without causing it to get stuck and bug players movement speed. Will see if running two mods using this method causes any bugs, but it works great right now on the one mod I use it in.
Would it not be easier to be able to change the values used by input manager to set the movement vector? Currently these are hardcoded to 1 when Apply___Force() methods are called. Maybe allowing these values to be changed would be the best way to affect how fast players move when the movement controls are used.

I could be wrong, and maybe someone else has a better idea. The input system is not one I know very deeply. I do think that using bool switches the way you describe is probably sub-optimal and fragile. Hopefully there's a better way, but well done for getting that to work at all. :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by l3lessed »

Thanks for the ideas. I'll look into it. The bool switch was the work around I found originally when digging into player object properties, but your idea of changing direct vector input value could be a hardier/better approach then saving and changing default values based on a bool switch.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by Hazelnut »

It would need some work to expose them, because they are literally hardcoded 1s right now. :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by l3lessed »

Its not an issue. Just requires a few extra checks and I think I'll be okay.

It would be nice to have a straight movement modifier object that modders can put values into, and it will handle the override for the player and not requiring a number of checks by the modder code.

Maybe if I can find some time, I'll take a swing at improving this in the base branch and submit it. I would love to have my name on the contributors list for DFU when full version drops to public. I really appreciate all the work the community put into getting the classic up and so moddable.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by l3lessed »

So the easiest fix I see for this is to turn the constant float dfWalkSpeed value in PlayerSpeedChanger to an accessible property instead of locking it down as a constant. Or, this can also be done to the classicToUnitySpeedUnitRatio float value. Both would have the same affect because they are used to compute base movement speeds for everything else.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by l3lessed »

That took only about two hours. First dev version dropped in the released mods area. I'll begin going at the SpeedChanger to update the way the movement overrides work, so they don't rely on a bool switch system.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: [Mod Request] Floor type affects movement speed

Post by l3lessed »

Now I get why this was turned into a simple override and not touched again. Outside doing a direct formula override within formulaHelper, this is a pain to setup to allow dynamic changes and keep a base value that is accurate.

This seems to largely work for allowing modders to override speeds on the fly without using switches.

Code: Select all

 public float GetBaseSpeed()
        {
            Entity.PlayerEntity player = GameManager.Instance.PlayerEntity;
            float baseSpeed = 0;
            float playerSpeed = player.Stats.LiveSpeed;
            if (playerMotor == null) // fixes null reference bug.
                playerMotor = GameManager.Instance.PlayerMotor;
            // crouching speed penalty doesn't apply if swimming.
            if (playerMotor.IsCrouching && !levitateMotor.IsSwimming)
                baseSpeed = (playerSpeed + dfCrouchBase) / classicToUnitySpeedUnitRatio;
            else if (playerMotor.IsRiding)
            {
                float rideSpeed = (GameManager.Instance.TransportManager.TransportMode == TransportModes.Cart) ? dfCartBase : dfRideBase;
                baseSpeed = (playerSpeed + rideSpeed) / classicToUnitySpeedUnitRatio;
            }
            else
                baseSpeed = SetWalkSpeed(walkSpeedOverride);
            return baseSpeed;
        }

        /// <summary>
        /// Get LiveSpeed adjusted for walking
        /// </summary>
        /// <param name="speedAdjustment">the amount to change players base walk speed by. Will reset to default speed if set to 0.</param>
        /// <param name="additiveAdjustment">figures out difference between previous and current speed adjustment and update walk speed with new additive adjustment speed.</param>
        /// <returns></returns>
        public float SetWalkSpeed(float speedAdjustment = 0, bool additiveAdjustment = false)
        {
            //if they use 0 for speed adjustment, reset the speed.
            if (speedAdjustment == 0)
                speedAdjustment = GetWalkSpeed(GameManager.Instance.PlayerEntity);

            if (previousWalkSpeed == 0)
                previousWalkSpeed = speedAdjustment;

            //checks to ensure it is set only once, even if modder has it in update loop.
            if(walkSpeedOverride != speedAdjustment)
            {
                //takes the current speed adjustment, subtracts it from the previous one to figure the difference, and then subtracts that difference from the previosu total speed to get the additive difference.
                if (additiveAdjustment)
                        speedAdjustment = previousWalkSpeed - (previousWalkSpeed - speedAdjustment);                                   

                //sets walk speed.
                walkSpeedOverride = speedAdjustment;
            }

            return walkSpeedOverride;
        }

        public bool RestoreWalkSpeed()
        {
            Debug.Log(previousWalkSpeed.ToString() + " | " + walkSpeedOverride.ToString());
            walkSpeedOverride = previousWalkSpeed;
            return true;
        }

        public float StoreWalkSpeed()
        {
            if (previousWalkSpeed != walkSpeedOverride)
                previousWalkSpeed = walkSpeedOverride;

            return previousWalkSpeed;            
        }
However, the one issue I'm running into now is how to allow modders to have a forced speed adjuster, so even when it updates, movement can be forced to still scale off a base, unchanging number. As an example, the Interactive Terrain mod technically will always set/need a base movement value, and as a result, it continually overrides other mod speed changes anytime a tile updates. As an example, my unsheathed slowdown gets cancelled out anytime a new tile is hit and the speed updated because it grabs the previous tile speed. I think we need a way to not only modify the current value (including additive methods), but we also need a base run and walk speed modifier value; it won't be used I imagine by many modders, outside my terrain mod, since most in-game speed changes are dynamic and timed.

My other idea was to create a stacking modifier that continual adds the differences to the modifier total. In this setup, modders would add their amount to the modifier total and than when done with their code, remove it from the total. This way, there is only one modifier value being adjusted up and down separate completely from the base value. It would need to be a percentage value though to ensure modders don't ever decrease speed below 0. So, terrain mod would tell the speedchanger to add 25% speed reduction to the current base value and assign that to a new stored value. At this point, then comes in the combat mod, adds another 35% speed reduction for being unsheathed to the previous stored base value. This would give the new stacked speed value. When modders are done, they then remove said value from the stacked modifier to return it to its previous value. This should allow modders to stack and remove as many speed changes as they want without heavy concern for other modders.

Any thoughts between these approaches?
Last edited by l3lessed on Tue Feb 23, 2021 12:43 am, edited 4 times in total.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

Post Reply