2016-11-07 3 views
0

축 고정 중 문제가 있습니다. 물건과 같이이 실물 크기의 바늘을 잡는데 사용할 수있는 도구가 두 가지 있습니다.한 축의 회전 유지 및 다른 축과의 정렬

Tool grabbing "needle"

난 그냥 그 자체 (로컬 Y) 주위의 회전을 유지하고 도구의 회전 나머지를 정렬 할 수 있어야합니다. 현재, 그러나 나는 단지과 같이 모든 축을 회전하는 방법을 알아낼 수 있습니다

Tool having grabbed "needle"

코드는 바로 다음과 같습니다

case 1: 
this.transform.rotation = leftParent.transform.rotation; 
this.transform.SetParent (leftParent); 
break; 
case 2: 
this.transform.rotation = rightParent.transform.rotation; 
this.transform.SetParent (rightParent); 
break; 

내가 시도하는 것 :

  • . 로컬 및 글로벌 회전 모두에서 설정, y 및/또는 w 회전 유지
  • = 새로운 쿼터니언은 로컬로 D 지구 회전의 Y 및/또는 내가 놓친 분명 뭔가가 있다면 그것은

알려 주시기 바랍니다 양육 후 바늘을 회전 부모 회전

  • 일치 한 후 바늘을 회전 승
  • 을 유지. 감사!

  • 답변

    0

    나는 당신이 찾고있는 것은 Transform.localRotation 또는 Tranform.localEulerAngles 생각 : 당신이 그 here에 대한 자세한 내용을 확인할 수 있습니다. 나는 이런 식으로 뭔가를 할 수 있습니다 귀하의 경우에는

    (당신의 "손"개체 형상이 예상대로 고려) : 그런데

    case1 : 
    //Adjust the rotation you want to keep here (I assume on Y axis in your case) 
    transform.SetParent(leftParent); 
    transform.localEulerAngles = new Vector3(0.0f, transform.localEulerAngles.y, 0.0f); 
    break; 
    case2 : 
    //Adjust the rotation you want to keep here (I assume on Y axis in your case) 
    transform.SetParent(rightParent); 
    transform.localEulerAngles = new Vector3(0.0f, transform.localEulerAngles.y, 0.0f); 
    break; 
    

    this 키워드는 혼자 transform 이후 상황에 필요하지 않습니다 스크립트가 첨부 된 변형 을 나타냅니다.