- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
- 纳金币
- 32806
- 精华
- 12
|
这几天看了一下AngryBots中的脚本,无奈水平有限有很多问题不明白。在脚本PlayerMoveController里面 Update函数中:
。。。。
// On PC, the cursor point is the mouse position
var cursorScreenPosition : Vector3 = Input.mousePosition;
// Find out where the mouse ray intersects with the movement plane of the player
var cursorWorldPosition : Vector3 = ScreenPointToWorldPointOnPlane (cursorScreenPosition, playerMovementPlane, mainCamera);
var halfWidth : float = Screen.width / 2.0f;
var halfHeight : float = Screen.height / 2.0f;
var maxHalf : float = Mathf.Max (halfWidth, halfHeight);
// Acquire the relative screen position
var posRel : Vector3 = cursorScreenPosition - Vector3 (halfWidth, halfHeight, cursorScreenPosition.z);
posRel.x /= maxHalf;
posRel.y /= maxHalf;
cameraAdjustmentVector = posRel.x * screenMovementRight + posRel.y * screenMovementForward;
cameraAdjustmentVector.y = 0.0;
// The facing direction is the direction from the character to the cursor world position
motor.facingDirection = (cursorWorldPosition - character.position);
motor.facingDirection.y = 0;
// Draw the cursor nicely
HandleCursorAlignment (cursorWorldPosition);
..............
// HANDLE CAMERA POSITION
// Set the target position of the camera to point at the focus point
var cameraTargetPosition : Vector3 = character.position + initOffsetToPlayer + cameraAdjustmentVector * cameraPreview;
// Apply some smoothing to the camera movement
mainCameraTransform.position = Vector3.SmoothDamp (mainCameraTransform.position, cameraTargetPosition, cameraVelocity, cameraSmoothing);
这段处理摄像机位置的代码中,变量cameraAdjustmentVector或者说posRel到底是什么意义呢?
|
|