Search Unity

square with curves Motion

Discussion in 'Physics' started by maormenashe, Jan 2, 2019.

  1. maormenashe

    maormenashe

    Joined:
    Oct 7, 2018
    Posts:
    20
    I have an object i want to move in a square motion, i also need the ability to have rounded corners.
    I saw lots of guides on how to make circular motion like this one:

    but none for what i'm looking for.

    I would appreciate your help.
     
  2. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    You could exponentiate your trig functions:

    Code (CSharp):
    1. public class Sphere : MonoBehaviour
    2. {
    3.     private float radius = 3f;
    4.     private float exp = 0.5f;
    5.     private float incr;
    6.  
    7.     void Update ()
    8.     {
    9.         incr += Time.deltaTime;
    10.         float cos = Mathf.Cos(incr);
    11.         float sin = Mathf.Sin(incr);
    12.         transform.position = new Vector3
    13.         (
    14.             radius * Mathf.Pow(Mathf.Abs(cos), exp) * Mathf.Sign(cos),
    15.             radius * Mathf.Pow(Mathf.Abs(sin), exp) * Mathf.Sign(sin),
    16.             0f
    17.         );
    18.     }
    19. }
    The resulting movement is not even though.
     
    maormenashe likes this.
  3. maormenashe

    maormenashe

    Joined:
    Oct 7, 2018
    Posts:
    20
    Thanks !! You've been a great help.