Search Unity

Rotate part way to a target

Discussion in 'Scripting' started by spiralgear, Aug 31, 2009.

  1. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    I am trying to make my characters upper body spin horizontally ( around the Y axis) when I move the mouse for a third person shooter. Right now I have an empty object acting as the target that spins when I move the mouse, and I have the lowest spine bone slerping to its rotation.



    But what I WANT to happen, is to have each of the 3 bones in the spine spin 1/3 of the way to the target rotation, instead of spinning the lowest one all the way.



    I have been struggling with this for 3 days now and I would appreciate any help.
     
  2. jmunozar

    jmunozar

    Joined:
    Jun 23, 2008
    Posts:
    1,091
    Hello,

    I had the same issue you had on a game I was developing, Sadly I couldnt rotate the half superior part of my char and stay static the lower part.

    that was because the animations overwrite my rotations :S

    if you happen to find a way, please let me know! :D
     
  3. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    The animation override isn't my problem, i've got that working. The problem is that I don't just want to rotate the lowest bone all the way to the target, I want each of the 3 bones to rotate 1/3 of the way there, I thought using




    Slerp(spine1.rotation,target.rotation,0.33)


    would do it, but it doesn't seem to work as expected.





    I don't think I am explaining myself very well, so I'll try to give an example:



    If the target rotation is 90 Degrees, the bottom bone should be facing 30 Degrees, the middle bone should be facing 60 Degrees, and the top bone should be facing 90 Degrees ( the target rotation).
     
  4. jmunozar

    jmunozar

    Joined:
    Jun 23, 2008
    Posts:
    1,091
    Sorry if I do not understand you well, but why not make an animation of the character spinning?
     
  5. spiralgear

    spiralgear

    Joined:
    Dec 13, 2007
    Posts:
    528
    No worries :) , im not explaining very well....






    Because he needs to face where the mouse is pointing, he is not just spinning in place, he is aiming at where the player is aiming.
     
  6. jmunozar

    jmunozar

    Joined:
    Jun 23, 2008
    Posts:
    1,091
  7. tomvds

    tomvds

    Joined:
    Oct 10, 2008
    Posts:
    1,028
    What is going wrong exactly?

    One thing I see, is that if spine2 and spine3 are parented, this code will not work, as assigning this slerp to spine2.rotation would also affect spine3 (resulting in a completely different slerp the next frame, having both spine2 and spine3 go berserk).