Hello, im upgrading and improving an old player system of mine. It works very nicely, cleaning up all the code mess I had and improving performance of it.
Im currently adding a sway to my player so when he moves left or right, it sways in the opposite direction just slightly so it feels natural when you move around.
In my script when I rotate the euler angles, it rotates like almost like it should but it twitches and it rotates more than the amount I set it too. Also if I try to move my mouse (This gameobject has the camera as a child object that contains a mouselook), my mouselook isint working. This is a very annoying issue, however im not sure if im using the right rotation. Either im supposed to use rotation, or euler. If anyone can help fix the twitching the issue id be thankful. Also if you would like I would like to know the difference between euler angles and rotation. Thanks.
#pragma strict
var cam : GameObject;
var cameraa : Camera;
var swayTilt : float = 0.0f;
var swaySmoothing : float = 0.0f;
private var rigid : Rigidbody;
function Start () {
rigid = gameObject.GetComponent(Rigidbody);
}
function Update () {
if(rigid.velocity.x != 0.0f){
cam.transform.rotation.z = Mathf.LerpAngle(cam.transform.rotation.z, -swayTilt, Time.deltaTime * swaySmoothing);
cam.transform.rotation.z = Mathf.Clamp(cam.transform.rotation.z, -swayTilt, swayTilt);
}
else {
cam.transform.rotation.z = Mathf.LerpAngle(cam.transform.rotation.z, cam.transform.rotation.z, Time.deltaTime * swaySmoothing);
cam.transform.rotation.z = Mathf.Clamp(cam.transform.rotation.z, -swayTilt, swayTilt);
}
}
EDIT: Oops forgot to post script, and i also changed it to rotation. The twitching is still there but less prominant but the whole camera is rotated Upside down. The twitching happens once it reaches the clamp then it twitches slightly.