Search Unity

Is there a way to match a relative angle?

Discussion in 'Scripting' started by Marscaleb, May 16, 2021.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    I kind of don't think this is something I can do, at least not directly. But I thought I would ask.

    I'm looking for a way to have an object match a rotation relative to how both objects are rotated, but not outright copy the rotation, just sort of add it to its current rotation.

    Since that doesn't make any sense, here's the long form of what I'm doing:
    I'm creating a sequence where the player can lift a rock and then throw it. To get the rock to move in tandem with the player animation I added a transform to the player to act as a position for the rock, and then created an animation for that transform rising up to where the player will hold the rock. The rock's script has it place its position to match that transform. Done.
    But I'd like to also animate the rotation of the rock. Not a lot, nothing super fancy, but it would look nicer.
    But I can't just copy out the rotation completely (like I do with the position) because that rotation is always facing the same direction. But the player could be facing the rock from any direction, and the rock could be a different direction too.
    So like, if the animation just has the rotation pitch toward the player a bit, I'd want the rock to tilt toward the player. But it can't just copy the same rotation, because the player is facing a different angle.
    So I'd want to copy the... relative rotation?

    Is that a thing I can do?
     
  2. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    1,037
    Nevermind, I just realized I can just parent the object to the other transform.
    Duh.