Search Unity

ETeeskiTutorials - Player Look Issue

Discussion in 'Scripting' started by equalspotato, Mar 12, 2012.

  1. equalspotato

    equalspotato

    Joined:
    Mar 11, 2012
    Posts:
    3
    i have been following ETeeskiTutorials tuts which are awesome btw :p but im having an issue with my gun it seems to pivot at the wrong place ive uploaded a video so you can see what i mean, thanks Scott

    http://www.youtube.com/watch?v=ag1no0PsBi4

    also this is the code i have;

    Code (csharp):
    1. var cameraObject : GameObject;
    2.  
    3. @HideInInspector
    4.  
    5. var targetXRotation : float;
    6.  
    7. @HideInInspector
    8.  
    9. var targetYRotation : float;
    10.  
    11. @HideInInspector
    12.  
    13. var targetXRotationV : float;
    14.  
    15. @HideInInspector
    16.  
    17. var targetYRotationV : float;
    18.  
    19.  
    20.  
    21. var rotateSpeed : float = 0.3;
    22.  
    23. var holdHeight : float = -0.5;
    24.  
    25. var holdForward : float = 1;
    26.  
    27. var holdSide : float = 0.5;
    28.  
    29. var racioHipHold : float = 1;
    30.  
    31. var hiptoAimSpeed : float = 0.1;
    32.  
    33. @HideInInspector
    34.  
    35. var racioHipHoldV : float;
    36.  
    37.  
    38.  
    39. function Update () {
    40.  
    41.  
    42.  
    43. if (Input.GetButton("Fire2"))
    44.  
    45. racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hiptoAimSpeed);
    46.  
    47. if (Input.GetButton("Fire2") == false)
    48.  
    49. racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hiptoAimSpeed);
    50.  
    51.  
    52.  
    53. transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) * Vector3(holdSide * racioHipHold, holdHeight * racioHipHold,holdForward));
    54.  
    55. targetXRotation = Mathf.SmoothDamp( targetXRotation, cameraObject.GetComponent(MouseLookScript).XRotation, targetXRotationV, rotateSpeed);
    56.  
    57. targetYRotation = Mathf.SmoothDamp( targetYRotation, cameraObject.GetComponent(MouseLookScript).YRotation, targetYRotationV, rotateSpeed);
    58.  
    59. transform.rotation = Quaternion.Euler(targetXRotation, targetYRotation, 0);
    60.  
    61. }
     
    Last edited: Mar 12, 2012
  2. benjwano

    benjwano

    Joined:
    Mar 5, 2012
    Posts:
    6
    hi,
    not sure if this helps, im no expert (learning from eteeski tutorials also)

    in my script, the following code / if statement is different.............
    ..........................................................................................
    if (Input.GetButton("Fire2") == false)
    racioHipHold = Mathf.SmoothDamp(racioHipHold, 0, racioHipHoldV, hiptoAimSpeed);
    ..........................................................................................
    I have a "1" (in place of "0" in your code)

    also not sure about your "holdForward" variable and the way its used in your code. I dont have that variable in my code as the script changes quite a bit as you go through the tutorials and i cant remember using it.

    hope you can sort it.

    nice gun model btw :)
     
    Last edited: Mar 12, 2012
  3. eteeski

    eteeski

    Joined:
    Feb 2, 2010
    Posts:
    476
    i think your parent object might be rotated a weird way. try setting the rotation back to (0,0,0) and line up the p-90 along the parent object's forward z axis.
     
  4. equalspotato

    equalspotato

    Joined:
    Mar 11, 2012
    Posts:
    3
    Thanks for your replys guys, sorry for my really late reply i was on holiday for a bit there,

    @benjwano thanks for your idea buddy but no such luck i think ours are different because after i couldn't get the rotation to work i started the next tutorial so thats kinda of half way between tuts;

    @eteeski thanks but unfortunately it didn't work for me, infact it made the gun face to the left, i think i may have screwed up my player capsule alignment or something