Search Unity

Using physics to fly

Discussion in 'Scripting' started by Krisper, Mar 15, 2013.

  1. Krisper

    Krisper

    Joined:
    Mar 24, 2011
    Posts:
    20
    I am working on making a bird fly similar to this video http://www.youtube.com/watch?v=rK6BAqctcRk&feature=youtu.be&t=1m24s

    This is going to be used in a VR project, I am going to use 3 trackers, one for my head and the other 2 on my hands. I have all the code worked out for getting the positions and orientations from the trackers. So now I am working on the bird flight.

    I have been playing for a while, found a few flight scripts and experimented, but I am just getting confused. I am not that experienced with physics in Unity. I was hoping someone might be able to explain what I need to look at in simple terms.

    So far I have the bird with a rigidbody, I have the mass as 0.01. To begin with I am applying a force to move it forward. I think I got this from an aeroplane script.
    Code (csharp):
    1.  
    2.         Vector3 AddPos = Vector3.forward;
    3.         AddPos = rigidbody.rotation * AddPos;
    4.         rigidbody.AddForce(AddPos * (Time.deltaTime));
    5.  
    I am just flapping the wings using key presses at the moment, but I am adding a vertical pulse with each wing flap using this.
    Code (csharp):
    1.  
    2.         Vector3 lift = transform.up * (Time.deltaTime * force);
    3.         bird.rigidbody.AddForce(lift, ForceMode.Impulse);
    4.  
    Eventually I will vary the force of the pulse based on the speed and distance of the wing flap.

    But I need to work out things like giving more lift based on speed when gliding. And being able to swoop down and up without crashing into the ground.

    And I need to make the bird turn when I tilt it left or right. My attempts at turning it send it spinning wildly.

    If anyone can give me some tips with this I would really appreciate it.
     
  2. Ralyx

    Ralyx

    Joined:
    Feb 10, 2013
    Posts:
    23
    This might seem obvious, but have you tried experimenting with the drag at all? Changing it mid-flight might help out a lot, especially when diving or turning.