I am using the smooth follow script for the camera right now. This does what I want it to do, but I also want it to function like the dark souls camera where it rotates around the player while maintaining its offset. could someone point me in the right direction on how to move the camera around the player.
Well you can use alittle circle math to figure this out. Like you can use a float to hold the current rotation incrament it by a speed then multipied by Time.deltaTime then you can create a radius then. With that currentRotation you can create a new rotation, then set the camera position to a radius * yourNewRotation.
void Start() {
currentRotationAngleYAxis = transform.eulerAngles.y;
currentRotationAngleXAxis = transform.eulerAngles.x;
}
// Update is called once per frame
void LateUpdate()
{
// Early out if we don't have a target
if (!target)
return;
// Calculate the current rotation angles
if (Input.GetKey (KeyCode.LeftArrow)) {
wantedRotationAngleYAxis = transform.eulerAngles.y + 1;
}
if (Input.GetKey (KeyCode.RightArrow)) {
wantedRotationAngleYAxis = transform.eulerAngles.y - 1;
}
if (Input.GetKey (KeyCode.UpArrow)) {
wantedRotationAngleXAxis = transform.eulerAngles. + 1;
}
if (Input.GetKey (KeyCode.DownArrow)) {
wantedRotationAngleXAxis = transform.eulerAngles.x - 1;
}
var wantedHeight = target.position.y + height;
var currentHeight = transform.position.y;
// Damp the rotation around the y-axis
//currentRotationAngleYAxis = Mathf.LerpAngle(currentRotationAngleYAxis, wantedRotationAngleYAxis, rotationDamping * Time.deltaTime);
currentRotationAngleYAxis = wantedRotationAngleYAxis;
currentRotationAngleXAxis = wantedRotationAngleXAxis;
// Damp the height
currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler(wantedRotationAngleXAxis, currentRotationAngleYAxis, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position = new Vector3(transform.position.x ,currentHeight , transform.position.z);
// Always look at the target
transform.LookAt(target);
}
}
So I have it rotating around the player just fine but I can get it to raise or lower like it does in dark souls. Any pointers on this? I don’t think adjusting the position is what I want but it doesn’t do anything when I try to increment the rotation in the x direction.
I’m not sure how dark souls camera works, but if you say it creates a bobbing effect, then you could use sin, and cos waves to get it to bob. This script was made by someone else in Javascript, but I converted it to C#, and it’s meant for head bobbing in FPS games, its the same concept you can use it.
The “mid” is pretty much the starting position for the camera, and the moving up and down does have to do with positions, rotations only rotate it at a certain point, so if you want a bobbing effect, then it’s position you’ll have to worry about.
I know that rotations only rotate at a certain point but the smooth follow script basically orients the camera then puts it at the center of the player then translates it to the offset. So I was thinking if I could just orient it to within [-60,60] on the x axis then it will translate the camera above the player and since there is the lookAt at the end it will always end up facing the player
// Damp the height
currentHeight = Mathf.Lerp(currentHeight, wantedHeight, heightDamping * Time.deltaTime);
// Convert the angle into a rotation
var currentRotation = Quaternion.Euler(currentRotationAngleXAxis, currentRotationAngleYAxis, 0);
// Set the position of the camera on the x-z plane to:
// distance meters behind the target
transform.position = target.position;
transform.position -= currentRotation * Vector3.forward * distance;
// Set the height of the camera
transform.position = new Vector3(transform.position.x ,currentHeight , transform.position.z);
it feels like the first 2 transform.position statements are the problem. Can’t figure out why though
if you press the up arrow it moves like an inch but doesn’t rotate the camera down continuously. same with the down arrow obviously. Could the Vector3.forward be negating , for lack of a better word, the incrementation of the x axis rotation?