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

[first person] Have a Viewmodel Slerp Rotation to the Player's Camera while Parented

Discussion in 'Scripting' started by dann96, Nov 20, 2016.

  1. dann96

    dann96

    Joined:
    Dec 6, 2014
    Posts:
    113
    I'm currently trying to make an fps script that has a view model that slerps to the players camera rotation. what I need is some way to have the viewmodel ignore the parented rotation and, instead, slerp to the camera rotation (similarly to what you might see in Half Life 2, if that's a good example).
     
  2. Scabbage

    Scabbage

    Joined:
    Dec 11, 2014
    Posts:
    268
    I don't really understand what you mean, but you can use the local vs global rotation of an object with someObject.transform.localRotation (relative to parent) and someObject.transform.rotation (global).
     
  3. dann96

    dann96

    Joined:
    Dec 6, 2014
    Posts:
    113
    What happens is that the viewmodel is a child of the FPS character object, making it rotate with the parent(the FPS character). What I want is to make the rotation of the viewmodel Slerp and not immediately rotate with the parent but rather slowly move towards the FPS character's rotation, all while still having the viewmodel be a child of the FPS character.
     
  4. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    What do you mean by "the viewmodel"?
     
  5. dann96

    dann96

    Joined:
    Dec 6, 2014
    Posts:
    113
    the gun model in a first-person perspective.
     
  6. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    If I get you right, you have a gameObject parented to another gameObject that rotates. But you want the child object to ignore the rotation of its parents. Right? If so, then I would suggestion two appraoches:
    1. Don't parent the gameObject at all, rather, make a script that copies the (speudo) parent gameObject position.
    2. Make a script that replaces the child object rotation by your own desired rotation.
    Both approaches would required to be applied in LateUpdate or by configuring the script execution order such that the parent moves before the child transform is modified.