c# –  “float” a capsule with a rigidbody element in unity?

c# – “float” a capsule with a rigidbody element in unity?

[ad_1]

I have been caught in a rut attempting to determine this out for some time now. What i would like is to have a capsule hover above the bottom at a set top to remove floor friction and make irregular surfaces much less of a problem. To do that although, I can not simply set the place of a gameobject to a selected top as a result of that appears a bit jittery and I desire a physics-driven character, which suggests minimizing the quantity of direct translation of place. One other strategy can be making use of a dampening power to power the participant again as much as the goal top by making use of a counterforce, which I can do, however can not scale with the rate of the participant to make the character’s rigidbody not hit the bottom from excessive heights. I additionally tried modifying the rate immediately by including a velocity to the detrimental falling velocity that stops on the minimal top

(one thing like this)

float correction = -rb.velocity.y * minheight/raydist;

rb.velocity += correction * upforce;

(upforce is simply Vector3.up)

My logic for that is that because the participant goes nearer to the bottom, the counter-velocity will strategy the precise velocity, slowing the participant to a cease on the minimal top. Not the way it works although apparently.

I wish to obtain a end result the place the participant can have a easy bounce after falling, and float at a set top over irregular surfaces and up slopes. If anybody is aware of how to do that, please assist, and clarify in as a lot element as you’ll be able to in order that I could perceive.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply