Using angrybot, I make the Player parent to MainCamera and achieve wild automatic camera rotation as camera rotate itself not the player. Then I open freemovementmotor.js and remove this:
// Make the character rotate towards the target rotation
if (faceDir == Vector3.zero) {
rigidbody.angularVelocity = Vector3.zero;
}
else {
var rotationAngle : float = AngleAroundAxis (transform.forward, faceDir, Vector3.up);
rigidbody.angularVelocity = (Vector3.up * rotationAngle * turningSmoothing);
}
}
The camera is stable but unfortunately I cant rotate as it is fixed.
My question how to make the camera rotate accordance to my player rotation? For example if Im looking back to see an object at the back of the player then I rotate and see it.
The code that you are removing controls the player, and is independent of the camera control.
The camera behavior is controlled in PlayerMoveController.js, in the Update() function. Try changing it to the following -
// HANDLE CAMERA POSITION
// To control the camera position relative to the player
var forwardOffset : float = 2.0f;
var upwardOffset : float = 2.0f;
// Set the camera above and behind the player by an offset
var cameraTargetPosition : Vector3 = character.position - character.forward * forwardOffset + character.up * upwardOffset;
// Apply some smoothing to the camera movement
mainCameraTransform.position = Vector3.SmoothDamp (mainCameraTransform.position, cameraTargetPosition, cameraVelocity, cameraSmoothing);
// Make the camera look at the new position of the player
mainCameraTransform.LookAt(character.position);
// This is used to control the direction in which the player will move
screenMovementSpace = Quaternion.Euler (0, mainCameraTransform.eulerAngles.x, 0);
screenMovementForward = screenMovementSpace * character.forward;
screenMovementRight = screenMovementSpace * character.right;
The last part is done to convert the player movement axes from fixed to relative.