- Home /
Quadrocopter flight
hi there,
i am trying to make a kind of flight simulator with a quadrocopter but i am having some (in fact a lot) problems with the control...
i think that it should be easy, but i dont get it...
i want to have a float "power" that makes it go up (in local Y) and than rotate it, so that the power can be used to go forward OR to go up... (if it is going forward it should go down at the same time)
my first test went quite goot, but my copter ignored collisions. so i tried to make a rigidbody and apply velocities on it. but its a lot more complicated -.-
so in fact i need rotation around the X,Y,Z axis and local up down on the local Y (with gravity)
do you have some ideas?
People here have many ideas but not a lot of time. What's the actual question?
how can i set a local y velocity, that also allows collision?
Answer by iwaldrop · Jan 23, 2013 at 08:31 PM
Attach a Rigidbody to your copter (sounds like you've already done this).
Use rigidbody.AddForce() and rigidbody.AddTorque() to manipulate it.
Quadrocopters usually either rotate their blades to vector their lift or control their RPMs individually; so you should probably attempt to apply force at the rotors. This will lead to an accurate simulation of how they work. If you're not worried about physics accuracy, then just use a single rigidbody for the fuselage and provide force/torque input to that.
thanks for the answer!
if i use addforce it gets faster and faster. is there a way to "read" the force/torque that is on it, for setting it back to 0 if i need to?
Oh...well, you mentioned the y axis, so gravity should be applied to counteract the force.
If you're not doing it that way then expriment with transform.Translate().
Again, IRL the copter's rotors would apply less force/thrust at one corner, allowing that side to drop, providing vectored thrust across the aggregate of rotors. If you're not doing it that way you're going to have to play with your 'simulation'.
okey... lets say, i make it applying force on each rotor... how do i make it? if i add force to each rotor they simply fly away... :/
i tried the Addforceposition but the force is in worldscale and not local :/
this is my code at the moment:
public GameObject rotor1, rotor2, rotor3, rotor4;
public float speed=200,time;
Vector3 rotorspeed1;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
rotorspeed1 = new Vector3(0,speed * Time.deltaTime,0);
if (Input.Get$$anonymous$$ey("s"))
{
ApplyForce(rigidbody, rotor1);
}
if (Input.Get$$anonymous$$ey("w"))
{
ApplyForce(rigidbody, rotor2);
}
if (Input.Get$$anonymous$$ey("d"))
{
ApplyForce(rigidbody, rotor3);
}
if (Input.Get$$anonymous$$ey("a"))
{
ApplyForce(rigidbody, rotor4);
}
//reset:
if (Input.Get$$anonymous$$ey("r"))
{
transform.position = new Vector3(0, 0.5f, 0);
transform.eulerAngles = new Vector3(0, 0, 0);
rigidbody.is$$anonymous$$inematic = true;
}
time += 1 * Time.deltaTime;
if (time > 1)
{
time = 0;
rigidbody.is$$anonymous$$inematic = false;
}
}// end update
void ApplyForce(Rigidbody body,GameObject r)
{
body.AddForceAtPosition(rotorspeed1, r.transform.position);
rigidbody.AddRelativeForce(rotorspeed1*3);
}
} //end class
Answer by Pysassin · Jan 23, 2013 at 10:10 PM
You can also use rigidbody.AddRelativeForce which would allow separate force numbers for up(y) forward(z) and side to side (x).
Your answer
Follow this Question
Related Questions
How to detect collision position and velocity? 2 Answers
Time when 2 objects will touch 1 Answer
When does a pos of a gameObject change from its velocity? 1 Answer
I want collision boxes to be precise without overlapping each other 1 Answer
Why is the relativeVelocity of a Collision always zero in OnCollisionEnter and OnCollisionStay? 0 Answers