All I can find are local velocity questions. Well I've been using
transform.InverseTransformDirection(rigidbody.velocity);
in my player's script to make my camera adjust its speeds according to the player.
Then I've been using
void Update ()
{
xPosition = player.transform.position.x;
yPosition = player.transform.position.y + 5f;
zPosition = player.transform.position.z - 14f;
xPosMulti = 1f + (playerScript.playerVel.x * 0.0001f);
yPosMulti = 1f + (playerScript.playerVel.y * 0.0001f);
zPosMulti = 1f + (player.rigidbody.velocity.magnitude * 0.01f);
transform.position = new Vector3(xPosition * xPosMulti, yPosition * yPosMulti, zPosition * zPosMulti);
}
in my camera. It works really well, even if it's a little too jumpy for me (Any way to make it feel more springy?), except that it "Looks" the wrong way when my player (Which is just a cube) is upside down. I want to cube to be able to rotate, so locking its z rotation isn't an option.
Further details: It's a side-scrolling game with a cube as a player. The camera follows the cube and when the cube goes faster, the camera looks further in that direction. Unfortunately, when the cube is upside-down, the camera looks backward instead of forward. I assume this is because my "transform.Inverse etc" line is measuring the velocity of my player in relation to its direction, not the direction in the world. How do I fix this?
↧