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. Dismiss Notice

Resolved Scaling animation to object scale

Discussion in 'Animation' started by miczac, Aug 9, 2023.

  1. miczac

    miczac

    Joined:
    Feb 28, 2021
    Posts:
    7
    Something I thought it would be a no brainer: scale an animation of an object based on the transform.localScale of a plane. My animation track moves the object in a normalized fashion (0 to 1 values), then I multiply animation values by the scale of the plane I want the object to move on. For some reason I have to multiply the scale value by 10 or so to have it actually cover the plane correctly. This is my scaling function (plane is at 0, 0, so I subtract half the scale to center the animation). The plane lays flat on the xz plane so the Y coordinate is left untouched.
    Code (CSharp):
    1. public static Vector3 AnimPos2WorldPos(in Vector3 pos, in Vector2 scale)
    2.     {
    3.         Vector2 hscale = scale / 2;
    4.         Vector2 apos = new Vector2(pos.x, pos.z);
    5.         apos = (apos * scale ) - hscale ;
    6.         return new Vector3(apos.x, pos.y, apos.y);
    7.     }
    Why wouldn't this work correctly?
     
  2. ijmmai

    ijmmai

    Joined:
    Jun 9, 2023
    Posts:
    188
    Fill up that function with debug commands for each value you are using. Those value may differ from what you think they are.
     
    miczac likes this.
  3. miczac

    miczac

    Joined:
    Feb 28, 2021
    Posts:
    7
    The plane is of dimensions 5x5 so scaling it by 10 will result in 50x50, hence the discrepancy