- Home /
Need help for player rotation and camera rotation
Hello I am new to Unity and C# and am working on a project for class. I have been looking online but have not found anything that works to how I want it to or it makes the camera spas when moving around. I have a current TPS game but my player doesn't rotate his body in the direction the player moves him, he just stays forward. I would like him to be able to rotate his body smoothly as the player moves around with WASD and the camera to follow, but I just want the camera to follow in a fixed height and position, probably using Cinemachine so I can add the Collider extension in case it collides with terrain it won't go inside. Here is my current PlayerMovement code for reference:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
public float speed = 0;
public Transform spawnshot;
private Rigidbody rb;
private float movementX;
private float movementY;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
private void OnMove(InputValue movementValue)
{
Vector2 movementVector = movementValue.Get<Vector2>();
movementX = movementVector.x;
movementY = movementVector.y;
}
private void FixedUpdate()
{
Vector3 movement = new Vector3(movementX, 0.0f, movementY);
rb.AddForce(movement * speed);
}
}
Here is how my camera is currently positioned, and it follows the player
Thanks for your help in advance! Please let me know if you have any questions so we can find a solution :)
Your answer
Follow this Question
Related Questions
How to keep the player on the left side o the screen? 2 Answers
How to make my player look in the direction of its movement? 3 Answers
How to rotate player rigidbody ? 1 Answer
How to make player move in the direction of where the camera is facing.(Y axis only) 7 Answers
Align the Camera to the head of the drawn lines in vectorsity 0 Answers