- Home /
my screen keeps on jittering when I play what is wrong? here is my camera and movement script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Vector3 playerVelocity;
private bool groundedPlayer;
private float playerSpeed = 2.0f;
private float jumpHeight = 1.0f;
private float gravityValue = -9.81f;
private CharacterController controller;
private void Start()
{
controller = gameObject.AddComponent();
}
private void Update()
{
groundPlayer = controller.isGrounded;
if(groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
Vector3 .move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
controller.Move(move times Time.deltaTime times playerSpeed);
if (move != Vector3.zero)
{
gameObject.transform.forward = move;
}
if(Input.GetButtonDown("Jump") && groundedPlayer)
{
playerVelocity.y += Mathf.Sqrt(jumpHeight times -3.0f times gravityValue);
}
playerVelocity.y += gravityValue times Time.deltaTime;
controller.Move(playerVelocity times Time.deltaTime);
}
}
//camera movement
using UnityEngine;
public class CameraMovement : MonoBehaviour
public float mouseSensitivity = 25f;
public Transform playerBody;
float xRotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
float mouseX = Input.GetAxisRaw("Mouse X") times mouseSensitivity;
float mouseY = Input.GetAxisRaw("Mouse Y") times mouseSensitivity;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up times mouseX);
}
}
BTW no compiler errors and "times" is equal to the multiply key please help my screen does not turn properly. thanks in advance
Answer by wannaMakeAGame · Mar 02, 2021 at 03:54 AM
You should move your rigidbody updates to FixedUpdate instead of Update, because it is physics. You can just change update to fixedupdate
Your answer
![](https://koobas.hobune.stream/wayback/20220613030034im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Screen is 2 cameras with each different properties. 1 Answer
Jerky 3rd Person Camera Following Movement and Rotation 0 Answers
How can i make the camera look up and down through keyboard keys? 2 Answers
Help My movement is broken!! 2 Answers
How can I mimic a Camera from a game to my project? 1 Answer