I am just starting out in unity…and I wanted to try to make a very simple fps movement script in C#
I did everything good and followed a tutorial, when I finished I boot up the game and starting moving a little bit…until I notice my mouse movement is very jittery! but for some reason, the WASD movement was not…I found this video by codemonkey it had the same problem that I have but it didn’t actually fix my issue
the video: https://www.youtube.com/watch?v=5JN9n1Lsp8g
I tried something different because it said that it was a problem with the input system…so I made something simple to move the player up when pressing the space bar, the player would float in the air for the 1st 0.5 seconds…but then it becomes hella jittery! so jittery that the player will just fall down despite the code is still executing! thank you for your time…and here is the code for both player movement and camera in C#
movement.cs:#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class movement : MonoBehaviour
{
public float speed = 10.0f;
private float horizontalInput;
private float forwardInput;
private float jumpInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
jumpInput = Input.GetAxis("Jump");
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
transform.Translate(Vector3.right * Time.deltaTime * speed * horizontalInput);
transform.Translate(Vector3.up * Time.deltaTime * speed * jumpInput);
}
}
look.cs:#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class look : MonoBehaviour
{
public float mouseSense = 100f;
public Transform PlayerBody;
float Xrotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void FixedUpdate()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSense * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSense * Time.deltaTime;
PlayerBody.Rotate(Vector3.up * mouseX);
Xrotation -= mouseY;
Xrotation = Mathf.Clamp(Xrotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(Xrotation, 0f, 0f);
}
}
I thought that changing the Input package manager Input-mode to Process Events In Dynamic Update, but didn’t work that what codemonkey mentioned