So, I’m trying to make my character hover in one place (2.5d platformer, by the way). I’ve successfully been able to complete the hovering portion through raycasting downwards to find out if the player is high enough off the ground (determined with a “hoverHeight” float), then using “AddForce” to push it up to that height. But now my problem is that the player floats downwards until it hits the floor, then hovers back up to the “hoverHeight”, then repeats. I want it to hover to the height, then stay there.
Here’s a snippet of the code.
var ray : Ray = Ray(transform.position, -Vector3.up);
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, hoverHeight)) {
var proportionalHeight : float = (hoverHeight - hit.distance) / hoverHeight;
var appliedHoverForce : Vector3 = Vector3.up * proportionalHeight * hoverForce;
rigidbody.AddForce(appliedHoverForce, ForceMode.Acceleration);
}