Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CB_Entity : GameObject;
- var CB_Cam : GameObject; //player camera
- var CB_SmoothAmount : int = 25;
- var CB_Update : float = 0.01;
- var CB_Offset : Vector3 = Vector3(-12, 35 , 0);
- var CB_SmoothArray : Vector3[];
- private var CB_lastupdate : float = 0;
- function Start(){ //function sets up array for use. Script is on camera so we start on camera for ease of debugging.
- //todo : tie this into update, so we can adjust smooth values while ingame
- CB_SmoothArray = new Vector3[CB_SmoothAmount + 2];
- for (i = 0 ; i <= CB_SmoothAmount + 1 ; ++i){
- CB_SmoothArray[i] = CB_Cam.transform.position;
- }
- }
- function LateUpdate () { //moving of gameobject is done in Update
- CB_lastupdate += Time.deltaTime;
- for(i = CB_lastupdate / CB_Update ; i >= 1 ; i-= 1){
- //if (CB_lastupdate >= CB_Update){
- CB_lastupdate -= CB_Update;
- SmoothCamera();
- }
- }
- function SmoothCamera(){ //xyz seperated from debugging
- //var x = CB_SmoothArray[0].x;
- //var y = CB_SmoothArray[0].y;
- //var z = CB_SmoothArray[0].z;
- var x = CB_Entity.transform.position.x;
- var y = CB_Entity.transform.position.y;
- var z = CB_Entity.transform.position.z;
- CB_SmoothArray[CB_SmoothAmount] = CB_Entity.transform.position;
- for (i = 0 ; i < CB_SmoothAmount ; ++i){
- x += CB_SmoothArray[i].x;
- y += CB_SmoothArray[i].y;
- z += CB_SmoothArray[i].z;
- CB_SmoothArray[i] = CB_SmoothArray[i + 1];
- }
- x /= CB_SmoothAmount + 1;
- y /= CB_SmoothAmount + 1;
- z /= CB_SmoothAmount + 1;
- //----
- x += CB_Offset.x;
- y += CB_Offset.y;
- z += CB_Offset.z;
- CB_Cam.transform.position = Vector3(x, y , z); //updates camera
- //CB_Cam.transform.position =CB_Entity.transform.position;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement