- Home /
How to make a rigidbody hover giving it an upward force? Mine still doesn't stay even when the upward force and graviational pull are equal.
I am trying to simulate a helicopter. Just now started with it. As a trial I took a cube, applied rigidbody to it setting its mass as 2. I then applied a constant force of 19.6 (since 2 * 9.8 = 19.) upwards. What I anticipated was that it would not move since upward and downward forces are exactly equal, but it actually moves downwards(though very slowly). Increasing the force by any amount moves it upwards. Am I wrong with the physics part or there is any else. Someone please help.
Answer by prof · Sep 07, 2014 at 09:39 AM
Something like this
void FixedUpdate(){
float yVel = rigid.velocity.y + Physics.gravity.y;
//Howering
rigid.AddForce(0, -yVel, 0, ForceMode.Acceleration);
//Altitude
rigid.AddForce(0, Input.GetAxis("Vertical") * 5, 0);
}
Answer by TheBombix95 · Dec 08, 2014 at 12:58 AM
hi Iqu, I've done this so many times that I've lost the count of it. Jokes apart, here's what I've done for mine:
function FixedUpdate () { //you have to apply the force Always in FixedUpdate function, otherwise in the Update
// function the force is not applied costantly, resulting in a slow fall towards the ground
//Here we apply a force to the rigidbody's local up vector and we multiply it by the rigidbody mass
//and the Absolute gravity up force.
//for now it should give you a go as long as your rigidbody doesn't tilt :S
rigidbody.AddRelativeForce( Vector3.up * (rigidbody.mass * Mathf.Abs(Physics.gravity.y) ) );
//How simple is that ?
}
if you need more info on helicopter's Physics just ask me, I'm developing a physics based helicopter game
Sorry, I've looked in the question date and it says that the year is the 2014
$$anonymous$$y mistake :S Been at it for too long today, many apologies(+1) :)
don't worry ;), i hope my answer will help someone that is looking for it. I've figured it out by thinking how an helicopter hovers. They compensate their mass and the gravity by countering those two forces and...tàdà. Here's the script. I'm currently developing a combat fly simulator based on real life formulas. If anyone needs help just ask me. Bye ;)
Answer by GameVortex · Sep 04, 2014 at 07:16 AM
Force and Gravitational acceleration is two different things. Force is applied with consideration of the object's mass while Gravity ignores mass. Try using Acceleration as the Forcemode: http://docs.unity3d.com/ScriptReference/ForceMode.html and you should get it to hover still. Although forcemode acceleration is probably not what you want to control your helicopter.
Normally a helicopter probably has to recalculate how much force it needs to apply to hover still. If it detects it moves upwards it has to decrease force and when it detects it moves down it has to increase force.
actually I used the physics component "constant force". Addforce doesnt seem to work here . Because "rigidbody.AddForce(new Vector3(0,9.8f,0),Force$$anonymous$$ode.Acceleration);" has to be put in update or fixedUpdate and it is not a constant force. It keeps giving a force of 9.8 upwards every frame and as a result it goes upwards.
This will give you force per second. rigidbody.AddForce(new Vector3(0,9.8f,0),Force$$anonymous$$ode.Acceleration) * Time.deltaTime;
No it doesn't work. we can't multiply time.deltatime to a statement like that. I tried " rigidbody.AddForce(new Vector3(0,9.8f,0)* Time.deltaTime,Force$$anonymous$$ode.Acceleration) " ins$$anonymous$$d, but even this does not work.
Your answer
Follow this Question
Related Questions
Applied force is increasing over time? 1 Answer
How to make an object hover(Against gravity) 1 Answer
hinge joint help? 0 Answers
Net Force between two objects... 1 Answer