Search Unity

Correction course for an object in motion

Discussion in 'General Discussion' started by CassClay, May 13, 2020.

  1. CassClay

    CassClay

    Joined:
    Mar 21, 2020
    Posts:
    69
    Hi guys,
    I've got an object moving.
    It's doing circles as follows
    x is Sin of Time squared
    and
    y is Cos of Time squared

    I want to correct the motion with 8 shaped pattern for full circle. And S shape for half an circle (1\pi)
    The correction is
    x equals Sin of Time squared * Cos Time squared
    and
    y equals Sin of Time squared.

    However if i just add x1 to x2 and y1 to y2 it stops doing circles instead drawing a tear like shape.
    I think it's just what's supposed to happen, it's just that i need it to phase shift that shape in space instead and still maintain the circular motion.
     
  2. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    This belongs in the Scripting forum.

    I think it depends on how you're doing motion. This is what I did for a circle:

    Code (CSharp):
    1.         var r = 5;
    2.         var offset_x = r * Mathf.Cos(flightAngle);
    3.         var offset_y = r * Mathf.Sin(flightAngle);
    4.         flightAngle += Time.fixedDeltaTime;
    5.         if (flightAngle >= (Math.PI*2))
    6.         {
    7.             flightAngle = 0;
    8.         }
    9.         var shift_x = offset_x - r * Mathf.Cos(flightAngle);
    10.         var shift_z = offset_y - r * Mathf.Sin(flightAngle);
    11.         this.transform.position -= new Vector3(shift_x, ((5 - (5f*numpkin.Genetics.Stats[NumpkinStats.Flight] / 100f)) + 1) * Time.fixedDeltaTime, shift_z);
    12.  
    This runs in a Coroutine.