Still Slow after code runs

Hi guys :slight_smile: I have just tweaked the FPSController Script so that when you are below 6y, you are slower and gravity is a little weaker. This is to simulate underwater effects, but when you come out of the water, the effects are still applied.

if ((transform.position.y < waterLevel) != isUnderwater) {
    isUnderwater = transform.position.y < waterLevel;
    m_WalkSpeed = 3;
    m_RunSpeed = 6;
    m_JumpSpeed = 12;
}

This is run in the Update() void so it will check every frame.

Does someone have a solution so when you come out of the water, the original movement is used? Thanks.

you don’t have code that resets the values to defaults.

I also notice that your naming of the variables implies they’re field members. Why modify the field members like that?

How about something like:

public class FPSController : MonoBehaviour
{

    public float m_WalkSpeed;
    public float m_RunSpeed;
    public float m_JumpSpeed;
   
    public float m_UnderWaterSpeedScale = 0.5f;

    void Update()
    {
        float spd = m_WalkSpeed; //or run, you probably have to test input
        if(transform.position.y < waterLevel) spd *= m_UnderWaterSpeedScale;
        //now use 'spd' instead
    }
   
}