- Home /
change objects Axis to match cameras rotation
So i am making a simple game at the moment a platforming one and i am working on the camera. so far i have been able to get the camera to follow the player as well the camera being able to move left and right with the mouses X axis. now the only issue i am having is trying to figure out how to match the objects axis with where the player is looking since when i turn the camera around pressing "W" will still make the object go the same direction. what i want it to do is the objects axis should follow where the camera is looking so if i go forward and switch my camera position the object should be going forward in respect of where the camera is looking
using UnityEngine;
public class Follow_Player : MonoBehaviour {
public Vector3 offset;
public Transform Player;
public float turnspeed = 4.0f;
// Update is called once per frame
void Update () {
transform.position = Player.position + offset;
}
private void LateUpdate()
{
offset = Quaternion.AngleAxis(Input.GetAxis("Mouse X") * turnspeed, Vector3.up) * offset;
transform.position = Player.position + offset;
transform.LookAt(Player.position);
}
this is the code for the camera which allows it to follow the player as well as allowing it to rotate on its x axis if someone can help me on how to make the axis match where the camera is looking or at least explain that would be wonderful thanks!
Your answer
Follow this Question
Related Questions
URGENT Cinemachine virtual camera while falling 1 Answer
How to rotate the camera with the player smoothly without the camera snapping back and forth? 2 Answers
Problem in rotating camera around a moving player 1 Answer
How to make slight Camera move and smooth 0 Answers
Camera gets stuck when cursor is locked 0 Answers