Game Development Reference
In-Depth Information
50.
//Vertical mouse displacement is interpreted
51.
//as vertical movement of the camera
52.
float yDelta = 0;
53.
if(invertYMovement){
54.
//Invert Y movement direction
55.
yDelta = -mouseDelta.y * verticalSpeed * Time.deltaTime;
56.
} else {
57.
//Use same Y movement direction
58.
yDelta = mouseDelta.y * verticalSpeed * Time.deltaTime;
59.
}
60.
61.
//Perform vertical movement of the camera
62.
transform.Translate(0, yDelta, 0, Space.World);
63.
64.
//Check if the Y position of the cam exceeds the allowed limits
65.
Vector3 newCameraPos = transform.localPosition;
66.
if(newCameraPos.y > maxCameraHeight){
67.
newCameraPos.y = maxCameraHeight;
68.
} else if(newCameraPos.y < minCameraHeight){
69.
newCameraPos.y = minCameraHeight;
70.
}
71.
72.
//Position the camera after fixing the Y position
73.
transform.localPosition = newCameraPos;
74.
75.
//Keep the camera looking at the character
76.
transform.LookAt(playerBody);
77.
78.
//Store the mouse position for the next frame
79.
lastMousePosition = Input.mousePosition;
Search WWH ::




Custom Search