Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Circular(Oval) Object Path

Discussion in 'Scripting' started by Ritt, Aug 12, 2015.

  1. Ritt

    Ritt

    Joined:
    Jul 22, 2015
    Posts:
    11
    Hello, I was just wondering how I could move an object around an oval shaped path such as the attached image. As well as an adjustable speed. I'm trying to learn some new things but can't seem to find anywhere on how to do this.

    Thanks a lot in advance!
     

    Attached Files:

  2. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    I think they keyword you are looking for is ellipse. I found a couple of decent answers on google.

    Basically it comes down to the formulas
    Code (csharp):
    1. x = a cos(time * speed);
    2. y = b sin(time * speed);
    where a and b are the ellipses radii on the x and y dimensions.
     
    Ritt likes this.
  3. sz-Bit-Barons

    sz-Bit-Barons

    Joined:
    Nov 12, 2013
    Posts:
    150
    the problem is: the movement speed is slower on the closer areas (in the picture at the top and bottom) because the formula actually moves on a stretched or shrinked circle...

    A long time ago I tried to find a solution for this problem but I couldn't...
     
    Ritt likes this.
  4. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    You're looking for (incomplete) elliptic integrals.
    But be warned: this is quite complex stuff. ;)
     
    Ritt likes this.
  5. sz-Bit-Barons

    sz-Bit-Barons

    Joined:
    Nov 12, 2013
    Posts:
    150
    Hmm... looks like a very interesting article.
    Just scrolled quickly through... not sure if it is able to keep the speed constant...

    However, I remembered how I solved the problem back then...
    I converted the ellipse into a polygon and used that approached shape for movement...
     
    Ritt likes this.
  6. TEBZ_22

    TEBZ_22

    Joined:
    Jan 28, 2014
    Posts:
    37
    If I remember right.. ( no guarantees there !)
    The speed of an object in elliptic orbit. The area covered by a line from the gravitational centre to the orbiter are a constant over time. In games we can often cheat a bit, and in this case might make the speed proportional the inverse of the current distance from the gravitational centre to the orbiter.