Search Unity

Question How to start an animation from an unspecified postition

Discussion in 'Animation' started by ljcorb762056, Apr 1, 2023.

  1. ljcorb762056

    ljcorb762056

    Joined:
    Mar 25, 2023
    Posts:
    4
    So I'm doing this "Interactive experience" thing as a project and all the animations are legacy because I'm using anim.Play(), was just wondering if i could scale/position objects without specifying the starting point? eg the user has 7 different positions, but once they hit a button no matter where they are they scale up to 1,1,1 and reposition to 0,0,0, without making 7 different animations because that is tedious.
    Doesn't have to use legacy animations as long as I can play it from a script, or maybe it is a script itself, not sure how it would work.

    I'm very new to animating and programming for unity, so I am just using the built in animator and visual studio, sorry if I don't understand a lot of it.
     
  2. Lifee00

    Lifee00

    Joined:
    Apr 13, 2021
    Posts:
    86
    I dont quite understand what you are trying to do there, could you explain further.
     
  3. ljcorb762056

    ljcorb762056

    Joined:
    Mar 25, 2023
    Posts:
    4
    In this project there are 7 possible positions the player could be in, but once they hit a specific button, no matter where they are, they should move to 0 and their scale is set to 1. The current way I have it set up is with separate animation clips for every possible position, but is there a cleaner way to do this?
     
  4. Lifee00

    Lifee00

    Joined:
    Apr 13, 2021
    Posts:
    86
    I mean, it really depends on your game, arent you controlling the movement and scale with a script, then just add +movement animation? Not sure why you would need 7 different animations for the same thing.
     
  5. ljcorb762056

    ljcorb762056

    Joined:
    Mar 25, 2023
    Posts:
    4
    What is the code for controlling with a script?
    The reason I have 7 different animations is because each movement is a premade one, and the animation clip is just moving the player from one position to another with 2 keyframes, it isn't very practical tho.

    Edit: I figured it out. For any other newbies like me, this is the code, using the first two lines for the scale and transform, and the last 2 for saving the position and returning to it later

    Code (CSharp):
    1. transform.localScale = new Vector3(1, 1, 1);
    2. transform.position = new Vector3(0, 0, 0);
    3.  
    4. yourGlobalVariableHere = transform.position;
    5.  
    6. transform.position = yourGlobalVariableHere;
     
    Last edited: Apr 2, 2023
  6. Lifee00

    Lifee00

    Joined:
    Apr 13, 2021
    Posts:
    86
  7. VictoriaCentci

    VictoriaCentci

    Joined:
    Apr 4, 2023
    Posts:
    1