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;
}
velocity.y = 0
isn't acceptable? \$\endgroup\$