Hey!
I want to make a game and I wrote some code that really suits my needs but I’m having a problem. When I’m moving the character and the camera at the same time I get this really weird jitter effect. When I’m moving only the camera or the character I don’t get this. Here is my code for the camera:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float speedH = 2.0f;
public float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 0.0f;
public Transform tran;
//This tran is the character transform
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
tran.rotation = Quaternion.Euler(0, yaw, 0);
}
}
And this is the character code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour {
public float speed;
private Rigidbody rb;
private Transform tr;
void Start()
{
rb = GetComponent<Rigidbody>();
tr = GetComponent<Transform>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
rb.MovePosition(tr.position + (tr.right * moveHorizontal * (speed * 0.01f) + (tr.forward * moveVertical * (speed * 0.01f))));
}
}
So I tried a lot of stuff but nothing works. How do I make this work without jittering?
EDIT: Here is the gif of the jittering. Look at the cube. You don’t see it when the gif is small. Just zoom in the page.
http://imgur.com/6yChVjI