First Person Controller flying upwards when moving mouse
I'm working on a parkour game and i had everything working perfectly, the character movement was fine, the looking around with the mouse was working well and collisions for jump pads were good. I was working on adding a restart function where it would teleport the player back to the starting position if they fell off the map, but on starting the game, the character started to move upwards if i looked anywhere, and i tried moving onto another platform and it started moving off the platform if i looked around and havent touched my keyboard once.
I'm thinking its something to have to do with the Rigidbody component i have on my player, but removing it would cause the collisions to stop working.
Can anybody help me out with this? Here's the code for the Mouse Look Script:
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using UnityEngine;
using System;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Application.targetFrameRate = 60;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
Thanks, Kai
Your answer
Follow this Question
Related Questions
Active Ragdoll with Kicks 0 Answers
How I can change script of MouseLook, Use GetComponent() instead. 1 Answer
My movement is not smooth 0 Answers
Gravity issue on MouvementController using RigidBody when going down a slope 0 Answers
How do you thrust an object to another object's position? 0 Answers