fork download
  1. //上方向でくるくる旋回させる
  2. count++;
  3. Vector3 normalVector = new Vector3(Mathf.Sin(count / 10.0f), 1, Mathf.Cos(count/10.0f));
  4. normalVector.Normalize();
  5.  
  6. //normalVectorの方向に回転させるための軸と量
  7. //キャラクターの頭上方向
  8. Vector cross = Vector3.Cross(transform.rotation * Vector3.up, normalVector).normalized;
  9. float dot = Vector3.Dot(transform.rotation * Vector3.up, normalVector);
  10.  
  11. //内積から角度に治す(1.0f~-1.0f)→0~180
  12. dot = (dot - 1.0f)*-90;
  13.  
  14. //適用
  15. //これでnormalVectorの方向に向いているはず
  16. transform.Rotate(cross, dot);
  17.  
  18. //結果を見る
  19. //normalVectorを示すSphereゲームオブジェクト
  20. aaa.transform.position = transform.position + normalVector * 5;
  21. //実際に向いている方向を示すSphereゲームオブジェクト
  22. aaa2.transform.position = transform.position + transform.rotation * Vector3.up * 5;
  23.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(2,0): error CS1525: Unexpected symbol `count'
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty