Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to calculate the Point Velocity? (No Rigidbody)

Discussion in 'Scripting' started by Aviation_Simmer, Jan 28, 2023.

  1. Aviation_Simmer

    Aviation_Simmer

    Joined:
    Aug 30, 2021
    Posts:
    110
    Hi! I am working on a flight simulator, with multilpe physics calculations per wing to make it as realistic as it gets. I cant just use the values of the rigidbody because the physics calculations are on the wings and not in the center of the rigidbody.

    The only thing I need not to get the wing working is the localVelocity... aka:
    Code (CSharp):
    1. transform.InverseTransformDirection(rb.GetPointVelocity(transform.position))
    It would be very nice if someone can tell or show me how to calculate this by my own.
    cheers!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    You might wanna check this guy out: he made an awesome aircraft physics package in Unity, with realtime airfoil lift, drag and torque calculations. He computes everything as these "Bivector" constructs and it works really well, giving you that kind of "flare and float" feeling as you near the stall.

    https://github.com/kurtdekker/Aircraft-Physics

    Discussion video:



    I use the system in my Pilot Kurt game and it was SUPER easy to integrate:

     
  3. Aviation_Simmer

    Aviation_Simmer

    Joined:
    Aug 30, 2021
    Posts:
    110
    Sure! I've tried this one once myself. BUT he is also using
    Code (CSharp):
    1. transform.InverseTransformDirection(rb.GetPointVelocity(transform.position))
    I just need to know how to get exactly that but without rigidbody
     
  4. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,992
    I'd imagine InverseTransformDirection is the hard part, and I've seen decent explanations of that elsewhere. Essentially, it gives you the movement relative to the way the airplane is facing. Suppose rb's realworld pointVelocity is something funny like (1.5, -0.6, 0.45). So it's moving east, a tad north, and a little bit down. But let's say that's exactly the direction the plan is facing. So all of that math gives (0,0,1.67) -- that point is moving at speed 1.67 directly "forward" to the plane. The technical term for "relative to the way I'm facing" is Local Coordinates.

    Thinking in world and local and going back and forth as needed is a common, useful trick, and easy once you know it.
     
  5. Aviation_Simmer

    Aviation_Simmer

    Joined:
    Aug 30, 2021
    Posts:
    110
    Thanks a lot!!! Basicly I just had to add the offset of the rb.getpointvelocity so its at the same spot as the physics calculations. upload_2023-1-28_17-39-8.png
    upload_2023-1-28_17-41-16.png
    Its hard to see here but the direction moves for every physic in that wing independently. exactly what I needed
     
    Kurt-Dekker likes this.