3D Player rotates Horizontally instead of Vertically when following mouse point direction
So im currently in the process of making a 3d top-down shooter game. I was originally using a capsule game object as a placeholder just to make sure my mechanics for the player movement script and the gun shooting mechanic worked, now that im switching out the capsule model with my imported model from 3ds max, the player is turning towards where i point the mouse but instead of the player turning vertically its turning horizontally. Like the head of my model is pointing towards the mouse direction and the feet point outwards. Below is my player controller script.
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private Rigidbody myRigidbody;
private Vector3 moveInput;
private Vector3 moveVelocity;
private Camera mainCamera;
public GunController theGun;
// Start is called before the first frame update
void Start()
{
myRigidbody = GetComponent<Rigidbody>();
mainCamera = FindObjectOfType<Camera>();
}
// Update is called once per frame
void Update()
{
moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput * moveSpeed;
Ray cameraRay = mainCamera.ScreenPointToRay(Input.mousePosition);
Plane groundPlane = new Plane(Vector3.up, Vector3.zero);
float rayLength;
if(groundPlane.Raycast(cameraRay, out rayLength))
{
Vector3 pointToLook = cameraRay.GetPoint(rayLength);
Debug.DrawLine(cameraRay.origin, pointToLook, Color.blue);
transform.LookAt(new Vector3(pointToLook.x, transform.position.y, pointToLook.z));
}
if (Input.GetMouseButtonDown(0))
theGun.isFiring = true;
if (Input.GetMouseButtonUp(0))
theGun.isFiring = false;
}
private void FixedUpdate()
{
myRigidbody.velocity = moveVelocity;
}
}
Your answer
Follow this Question
Related Questions
How to move object to the right? 1 Answer
drag AND drop push and pull object 0 Answers
How to make a platform move between multiple points? 2 Answers
Looking for help with orbit/follow player script vector math calculations 1 Answer
How to make individual pressure plates translate up when stepped on, within a parent? 1 Answer