纳金网

标题: 魔兽视角的代码 [打印本页]

作者: 狂风大尉    时间: 2015-2-28 20:23
标题: 魔兽视角的代码
魔兽视角的代码
  1. /*

  2. This camera smoothes out rotation around the y-axis and height.

  3. Horizontal Distance to the target is always fixed.

  4. There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves.

  5. For every of those smoothed values we calculate the wanted value and the current value.

  6. Then we smooth it using the Lerp function.

  7. Then we apply the smoothed values to the transform's position.

  8. */

  9. // The target we are following

  10. var GO_T:GameObject;

  11. var target : Transform;

  12. var camera1:Camera;

  13. // The distance in the x-z plane to the target

  14. var distance = 10.0;

  15. // the height we want the camera to be above the target

  16. var height = 5.0;

  17. // How much we

  18. var heightDamping = 2.0;

  19. var rotationDamping = 3.0;

  20. // Place the script in the Camera-Control group in the component menu

  21. @script AddComponentMenu(“Camera-Control/Smooth Follow”)

  22. function LateUpdate () {

  23. // Early out if we don't have a target

  24. if (!target)

  25. return;

  26. distance += Input.GetAxis(“Mouse ScrollWheel”)*5;

  27. if(distance>10){

  28. distance=10;

  29. }

  30. else if(distance<0){

  31. distance=1;

  32. }

  33. if(Input.GetKey(KeyCode.Mouse1)){

  34. height+= Input.GetAxis(“Mouse Y”) *5;

  35. if(height>10){

  36. height=10;

  37. }

  38. else if(height<0){

  39. height=0;

  40. }

  41. }

  42. transform.LookAt (target);

  43. // Calculate the current rotation angles

  44. wantedRotationAngle = target.eulerAngles.y;

  45. wantedHeight = target.position.y + height;

  46. currentRotationAngle = transform.eulerAngles.y;

  47. currentHeight = transform.position.y;

  48. // Damp the rotation around the y-axis

  49. currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);

  50. // Damp the height

  51. currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);

  52. // Convert the angle into a rotation

  53. currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);

  54. // Set the position of the camera on the x-z plane to:

  55. // distance meters behind the target

  56. transform.position = target.position;

  57. transform.position -= currentRotation * Vector3.forward * distance;

  58. // Set the height of the camera

  59. transform.position.y = currentHeight;

  60. // Always look at the target

  61. transform.LookAt (target);

  62. var hit : RaycastHit;

  63. var fwd = transform.TransformDirection (Vector3.forward);

  64. if (Physics.Raycast (GO_T.transform.position, -fwd,hit, 3)) {

  65. if(hit.transform.tag==“wall”){

  66. camera1.depth=1;

  67. camera1.enabled=true;

  68. print (“aaaaaa”);

  69. }

  70. }

  71. if (Physics.Raycast (GO_T.transform.position, -fwd,hit, 3)==false) {

  72. camera1.depth=0;

  73. camera1.enabled=false;

  74. print (“dddddddd”);

  75. }

  76. }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5