Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. var CB_Entity : GameObject;
  2. var CB_Cam : GameObject; //player camera
  3.  
  4. var CB_SmoothAmount : int = 25;
  5. var CB_Update : float = 0.01;
  6. var CB_Offset : Vector3 = Vector3(-12, 35 , 0);
  7.  
  8. var CB_SmoothArray : Vector3[];
  9. private var CB_lastupdate : float = 0;
  10.  
  11. function Start(){ //function sets up array for use. Script is on camera so we start on camera for ease of debugging.
  12. //todo : tie this into update, so we can adjust smooth values while ingame
  13. CB_SmoothArray = new Vector3[CB_SmoothAmount + 2];
  14. for (i = 0 ; i <= CB_SmoothAmount + 1 ; ++i){
  15. CB_SmoothArray[i] = CB_Cam.transform.position;
  16. }
  17. }
  18.  
  19. function LateUpdate () { //moving of gameobject is done in Update
  20. CB_lastupdate += Time.deltaTime;
  21. for(i = CB_lastupdate / CB_Update ; i >= 1 ; i-= 1){
  22.  
  23. //if (CB_lastupdate >= CB_Update){
  24. CB_lastupdate -= CB_Update;
  25. SmoothCamera();
  26. }
  27. }
  28.  
  29. function SmoothCamera(){ //xyz seperated from debugging
  30. //var x = CB_SmoothArray[0].x;
  31. //var y = CB_SmoothArray[0].y;
  32. //var z = CB_SmoothArray[0].z;
  33. var x = CB_Entity.transform.position.x;
  34. var y = CB_Entity.transform.position.y;
  35. var z = CB_Entity.transform.position.z;
  36. CB_SmoothArray[CB_SmoothAmount] = CB_Entity.transform.position;
  37. for (i = 0 ; i < CB_SmoothAmount ; ++i){
  38. x += CB_SmoothArray[i].x;
  39. y += CB_SmoothArray[i].y;
  40. z += CB_SmoothArray[i].z;
  41. CB_SmoothArray[i] = CB_SmoothArray[i + 1];
  42. }
  43. x /= CB_SmoothAmount + 1;
  44. y /= CB_SmoothAmount + 1;
  45. z /= CB_SmoothAmount + 1;
  46. //----
  47.  
  48. x += CB_Offset.x;
  49. y += CB_Offset.y;
  50. z += CB_Offset.z;
  51. CB_Cam.transform.position = Vector3(x, y , z); //updates camera
  52. //CB_Cam.transform.position =CB_Entity.transform.position;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement