查看: 957|回复: 0
打印 上一主题 下一主题

[其他] 魔兽视角的代码

[复制链接]

2722

主题

42

听众

3万

积分

资深设计师

Rank: 7Rank: 7Rank: 7

纳金币
38268
精华
111

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2015-2-28 20:23:01 |只看该作者 |倒序浏览
魔兽视角的代码
  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. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-8-20 04:43 , Processed in 0.064718 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部