Hey. I’m a pretty big noob when it comes to unity.
I’m self taught when it comes to programming, I finally got myself to work on a game, or better said a character controller.
I wanted to mimic the controlls of a game called Nier:Automata, atleast the basic feel of moving around and how the camera behaves. So far I’ve been able to move the character in relation to the camera.
I calculate the angle this way:
void Update () {
Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
input.Normalize();
if (input != Vector2.zero)
{
float targetRotation = Mathf.Atan2(input.x, input.y) * Mathf.Rad2Deg + cameraBase.transform.eulerAngles.y;
targetRotation = Mathf.SmoothDampAngle(transform.rotation.eulerAngles.y, targetRotation, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, targetRotation, 0f);
}
bool running = Input.GetKey(KeyCode.LeftShift);
float speed = ((running) ? runSpeed : walkSpeed) * input.magnitude;
rigidbody.MovePosition(transform.position + transform.forward * speed * Time.deltaTime);
}
As you can see I just move the character by turning him in the apropriate direction and then adding a forward force.
This however has one major difference looking at my inspiration Nier:Automata - When you move horizontally in my “game” the character just moves on the horizontal axis. However in Nier:Automata, the Character runs in a big circle.
My camera is focused on the character by just this code
transform.position = target.position - offset * currentZoom;
I can rotate the camera around the character with this code
mouseX = Input.GetAxis("Mouse X");
mouseY = Input.GetAxis("Mouse Y");
inputX = Input.GetAxis("Joystick Horizontal");
inputY = Input.GetAxis("Joystick Vertical");
rotationY += (mouseX + inputX) * inputSensitivity * Time.deltaTime;
rotationX += (mouseY + inputY) * inputSensitivity * Time.deltaTime;
rotationX = Mathf.Clamp(rotationX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotationX, rotationY, 0.0f);
transform.rotation = Quaternion.Lerp(transform.rotation, localRotation, smoothRotation);
So do you have any idea on how I can rotate the character like in nier:automata in my script?