Skip to content
This repository
  • 3 commits
  • 8 files changed
  • 0 comments
  • 1 contributor
Aug 12, 2012
drbergeron Updated camera
Should be working now except for adding colliders for terrain features.

added camera containers, if logic for rotating so Ray's aren't being
calculated when not needed.
b264f2e
drbergeron updated unity for camera changes
added camera container
8b07e93
Aug 13, 2012
drbergeron i can't figure out how to not commit things
fucking github
ae5a225
31  Assets/Engine/Controllers/CameraController.cs
@@ -3,6 +3,7 @@
3 3
 
4 4
 public class CameraController {
5 5
 	private GameObject camera;
  6
+	private GameObject cameraContainer;
6 7
 	private float cameraSpeed;
7 8
 	private float cameraHeight;
8 9
 	private float cameraScrollSpeed;
@@ -11,6 +12,7 @@ public class CameraController {
11 12
 	
12 13
 	//Constants
13 14
 	private const string MAIN_CAMERA_GAMEOBJECT_NAME = "Main Camera";
  15
+	private const string MAIN_CAMERA_CONTAINER_NAME = "CameraContainer";
14 16
 	private const float DEFAULT_CAMERA_SPEED = 1f;
15 17
 	private const float DEFAULT_CAMERA_HEIGHT = 20.0f;
16 18
 	private const float DEFAULT_CAMERA_SCROLL_SPEED = 10.0f;	
@@ -26,23 +28,40 @@ public class CameraController {
26 28
 		cameraHeight = DEFAULT_CAMERA_HEIGHT;
27 29
 		cameraScrollSpeed = DEFAULT_CAMERA_SCROLL_SPEED;
28 30
 		camera = GameObject.Find(MAIN_CAMERA_GAMEOBJECT_NAME);
  31
+		cameraContainer = GameObject.Find(MAIN_CAMERA_CONTAINER_NAME);
29 32
 	}
30 33
 	
31 34
 	public void logic() {		
32 35
 			
33 36
 	}
34 37
 
35  
-	public void modifyCameraPosition(float horizontalModifier, float verticalModifier, float rotateModifier){			
36  
-		camera.transform.RotateAround(Vector3.zero,Vector3.up,Time.deltaTime * DEFAULT_CAMERA_ROTATE_SPEED * rotateModifier);	
37  
-		targetPosition = camera.transform.position;			
38  
-		targetPosition.Set(targetPosition.x + horizontalModifier * cameraSpeed, cameraHeight, targetPosition.z + verticalModifier * cameraSpeed);
39  
-		camera.transform.position = targetPosition;	
  38
+	public void modifyCameraPosition(float horizontalModifier, float verticalModifier, float rotateModifier){
  39
+		if (rotateModifier != 0 ){
  40
+			Ray ray = camera.camera.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
  41
+			RaycastHit hit;
  42
+ 
  43
+	        if (Physics.Raycast(ray, out hit)){
  44
+	            cameraContainer.transform.RotateAround(hit.point,Vector3.up, 
  45
+						Time.deltaTime * DEFAULT_CAMERA_ROTATE_SPEED * rotateModifier);	
  46
+			}else
  47
+	            cameraContainer.transform.RotateAround(Vector3.zero,Vector3.up, 
  48
+						Time.deltaTime * DEFAULT_CAMERA_ROTATE_SPEED * rotateModifier);
  49
+		}
  50
+		Transform thisTrans = cameraContainer.transform;
  51
+		thisTrans.transform.Translate(horizontalModifier * cameraSpeed,0,verticalModifier * cameraSpeed,Space.Self);
  52
+		cameraContainer.transform.position.Set(thisTrans.transform.position.x,cameraHeight,
  53
+					thisTrans.transform.position.z);	
40 54
 				
41 55
 	}
42 56
 	
43 57
 	public void modifyCameraHeight(float modifier){
44  
-		cameraHeight -= modifier * cameraScrollSpeed;
  58
+		float oldCameraHeight = cameraHeight;
  59
+		cameraHeight += modifier * cameraScrollSpeed;
45 60
 		enforceBounds();
  61
+		
  62
+		Transform thisTrans = cameraContainer.transform;
  63
+		thisTrans.transform.Translate(0,oldCameraHeight - cameraHeight,0);
  64
+		cameraContainer.transform.position = thisTrans.transform.position;
46 65
 	}
47 66
 
48 67
 	private void enforceBounds(){
2  Assets/Materials.meta
... ...
@@ -0,0 +1,2 @@
  1
+fileFormatVersion: 2
  2
+guid: e2b76b05f194b734bbe05743b1735fad
BIN  Assets/Materials/CanonBarrell.mat
Binary file not shown
2  Assets/Materials/CanonBarrell.mat.meta
... ...
@@ -0,0 +1,2 @@
  1
+fileFormatVersion: 2
  2
+guid: 76f1cfe183c6d3e40b711dc3958c646f
BIN  Assets/Materials/NoobBrick.mat
Binary file not shown
2  Assets/Materials/NoobBrick.mat.meta
... ...
@@ -0,0 +1,2 @@
  1
+fileFormatVersion: 2
  2
+guid: 3a1a2a39153442749af9696d94542102
2  Assets/Textures.meta
... ...
@@ -0,0 +1,2 @@
  1
+fileFormatVersion: 2
  2
+guid: 3da6e2fead6d534469f5cc53252c4ff7
BIN  Assets/helloworld.unity
Binary file not shown

No commit comments for this range

Something went wrong with that request. Please try again.