Im trying to get a third person camera to work.
Ive got a vector3 that im transforming so that the position of the camera seems as its in the local space of the player.
Every time the player rotates the camera this vector3 is updated to reflect the new location.
Im also casting a Linecast towards this vector3. If there’s anything inbetween, the camera’s put at that position. If not, it is positioned at the desired vector3. Better yet, it moves towards it.
However, it all doesn’t seem to work. Even my teacher at school in Unity can’t help me.
What I want to do is 2 options:
Transform the vector3 into a direction and multiply this direction with a distance, then set the camera on the player’s position + this number.
Or I make the Linecast (which it currently doesn’t).
Is there anyone out there with the expertise to help me? I’ve grown quite desperate…
Im using the follow code:
transform.RotateAround(Player.transform.position, Player.transform.right, Input.GetAxis("Mouse Y") * Time.deltaTime * 2);
transform.RotateAround(Player.transform.position, Player.transform.up, Input.GetAxis("Mouse X") * Time.deltaTime * 5);
print(Input.GetAxis("Mouse X"));
if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0) {
distanceFromPlayer = Player.transform.InverseTransformPoint(transform.position);
desiredDirection = new Vector3(distanceFromPlayer.x / distanceFromPlayer.magnitude, distanceFromPlayer.y / distanceFromPlayer.magnitude, distanceFromPlayer.z / distanceFromPlayer.magnitude);
}
...
transform.position = Player.transform.position + (desiredDirection * realDistance);
transform.LookAt(new Vector3(Player.transform.position.x, Player.transform.position.y + 0.5f, Player.transform.position.z), currentUp);
Where realDistance is equal to 12f currently.
The issue is that using this, the rotation when doing RotateAround is somehow snapping to 1 or -1 on the x and z axisses. Could this be due to conflicts between the RotateAround and LookAt? I’m clueless.
(And yes, I realize that what I do is the same as .normalize. I tried using this technique because the .normalize gave me the same rounding-up issue)
[/code]