# How to “reset” velocity.y when entering water?

I'm using a raycast controller and kinematic ridigbody.

The way I've got my project set up is that I have a set of default values, such as gravity, jump height, etc., and when I enter a certain trigger, such as water, these values change (or, more specifically, I override these values temporarily).

My velocity.y += gravity * time.deltaTime, but there are some bugs if I jump into the water. For example, if I jump in from above then the velocity.y does not change in the water until I collide with the bottom of the water. Essentially it looks like I'm performing a normal jump, and only once I land will the changed gravity in the water trigger affect my movement. Also, if I jump in the water trigger from the side it sometimes propels me very high in the air.

When I print out the gravity value it does change immediately when I enter the water, but it seems the downward force from falling is never changed until I hit the bottom of the ocean floor.

public ControllerParameters2D Parameters { get { return overrideParameters
?? defaultParameters; } } //Returns updated parameters, or default
//parameters if overrideParameters is null

public void LateUpdate()
{
JumpInSeconds -= Time.deltaTime; //Calculates how long until the player can jump again

velocity.y += Parameters.gravity * Time.deltaTime; //Adds the force of gravity to the character's y velocity, scaled per time

Move(Velocity * Time.deltaTime); //Moves the character per its velocity, scaled by time
}

public void OnTriggerEnter2D(Collider2D other)
{
var newParameters = other.gameObject.GetComponent<ControllerPhysicsVolume2D>();

if (newParameters == null)
{
return;
}

overrideParameters = newParameters.NewParameters;
}

public void OnTriggerExit2D(Collider2D other)
{
var newParameters = other.gameObject.GetComponent<ControllerPhysicsVolume2D>();

if (newParameters == null)
{
return;
}

overrideParameters = null;
}

• Any reason why velocity.y = 0 isn't acceptable? – Jay Jan 22 '18 at 3:20
• This worked. Can I tell you, I've spent nearly 60 hours this week trying to perfect a ladder system, and decided to take a break and try this today. I've been so mentally overwhelmed with the ladders that I guess I just didn't think of this very obvious solution myself...Thank you very much! – Ginger and Lavender Jan 22 '18 at 3:32
• Do you have separate time deltas for the different portions of the jump (time spent in air, time spent in water)? – Acccumulation Jan 22 '18 at 19:18

OnTriggerEnter2D(Collider2D){