- Home /
Question by
Dylko4ever · Jan 23 at 01:35 PM ·
positionbugy-axis
Y position changes randomly,Y position changes weirdly
Hi,
I am new to unity, and i am making a simple parkour game. Right now you can look around and walk around. But i have a strange bug where the Y position of the player changes from 1 to 1.08 to 1.28 to 1.7 etc. I dont know what is causing this strange bug. I have a rigidbody and a character controller. i have the rotation constraints locked. Here is my movement code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
void Update() {
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
}
}
Here is my MouseLook code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MouseLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform player;
public Text parkourText;
float xRotation = 0f;
void FixedUpdate()
{
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);
if (parkourText.text == "") {
Cursor.lockState = CursorLockMode.Locked;
player.Rotate(Vector3.up * mouseX);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
}
}
Does anyone know how to fix this?
Comment