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

Question Make another object move along with animation?

Discussion in '2D' started by Inverzus, Aug 10, 2020.

  1. Inverzus

    Inverzus

    Joined:
    Jun 26, 2020
    Posts:
    12
    Hello, so I'm currently trying to make a 2D Space dogfighting game and am trying to work out some basic animation work atm. So my player ship has a "transforming" feature though all it really is the sides of the ship expanding outwards from the core of the ship. But the problem is that there are objects attached to the sides of the ship, mainly the main guns and missile rack. I made them separate (A child of the ship gameobject) so that I can implement multiple pieces of equipment for the player. So in my current setup, wouldn't I also need transformation animations for the weapons, which is really just them moving side to side? Is there a way to move the attached objects along with the sides of the ship without resorting to additional animations?
     
  2. GrizzlyPunchGames

    GrizzlyPunchGames

    Joined:
    May 21, 2020
    Posts:
    11
    Hi,
    You can do it by code
    Code (CSharp):
    1. public Transform ObjectToMove;
    2.  
    3. //Function you want to call when your objects should be moved
    4. public void ChangePositions()
    5. {
    6. ObjectToMove.position = new Vector3(x,y,z); //x,y,z are positions you want your objects to me moved to
    7. }