I want a hovercraft that’s y-position is never affected by collisions. My solution was going to be to have the y-translation frozen, but to unfreeze it during hover and gravity methods. The code below is what I’m using, but the y position never changes. Does anyone know why and how to get around this?
I have also tried a system with a virtualYVelocity variable that updates gameObject.transform.y, but that creates a ton of problems.
private void ApplyHover()
{
SetMovementonstraints();
RaycastHit hit;
bool hitAnything = Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, hoverDistance);
if(hitAnything canSteer)
{
rigidbody.AddForce(transform.up * Time.deltaTime * (hoverForce * (hoverDistance - hit.distance)));
}
ArtificialGravity();
SetNormalConstraints();
}
private void ArtificialGravity(){
rigidbody.velocity += transform.up * gravity;
}
private void SetNormalConstraints(){
rigidbody.constraints = RigidbodyConstraints.FreezeRotation | RigidbodyConstraints.FreezePositionY;
}
private void SetMovementonstraints(){
rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
}