Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How do I add transform.position to an object on top of an animation?

Discussion in 'Animation' started by AcidmanRPGz, Apr 25, 2021.

  1. AcidmanRPGz

    AcidmanRPGz

    Joined:
    Feb 14, 2020
    Posts:
    10
    So basically, I've set up a script that will move my weapon viewmodel from left to right and also up and down with the movement of my mouse. However, the thing I'm trying to move is animated when I run, and thus it will not move, and I don't feel like redoing all my weapon animations which took me a good 3 or 4 hours by creating a new object to move with the mouse. Is there anything I can do?

    Code (CSharp):
    1. gunSwayer.transform.position = new Vector2 (Input.GetAxis("Mouse X") * swayMultiplier, Input.GetAxis("Mouse Y") * swayMultiplier);
    This is what I have attempting to do it ATM
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,554
    Just put that code in LateUpdate.
     
  3. AcidmanRPGz

    AcidmanRPGz

    Joined:
    Feb 14, 2020
    Posts:
    10
    OK... that Kind of worked. it now moves left and right, but not the weapon holder is frozen in place, so I don't know what that's about, but it's a start.