- Home /
Question by
ixdrone · May 08, 2017 at 12:55 PM ·
unity 5rotationrigidbodycamera-movementcamera rotate
How can I rotate my camera when player has rigidbody?
Firstly, sorry for bad English.
If my settings like that:
Player Rigidbody: Example logic of rotation code of Player which is inside of Player script:
transform.Rotate(0f, -90f, 0, Space.World);
MainCamera Script:
public class CameraController : MonoBehaviour {
[SerializeField]Transform target; // PLAYER
private Vector3 defaultDistance = new Vector3(0f,4.5f,-3f);
private float rotationDamp = 5f;
private Transform cameraPosition;
private Vector3 toPos;
private Vector3 curPos;
void Awake(){
cameraPosition = transform;
}
void LateUpdate(){
toPos = target.position + (target.rotation * defaultDistance);
curPos = Vector3.Lerp (cameraPosition.position, toPos, Player.getCurrentSpeed () * 0.125f);
cameraPosition.position = curPos;
Quaternion toRot = Quaternion.LookRotation (target.position - cameraPosition.position, target.up);
Quaternion curRot = Quaternion.Slerp (cameraPosition.rotation, toRot, rotationDamp * 0.125f);
cameraPosition.rotation = curRot;
}
}
Everything is well, but when I change player's rigid body settings like the image above, camera acts like crazy.
How can I do that camera act like in the first rigidbody settings if player has rigidbody settings like in the second image?
If there is a way to spin the player like the rigid body in the second image with the rigidbody in the first image, it will be better?
screen-shot-2017-05-04-at-135145.png
(21.1 kB)
screen-shot-2017-05-04-at-135153.png
(21.4 kB)
Comment