- Home /
Character flickering when moving
Hello to everyone. I have a problem, my character was flickering when moving, i don't know why. I'm confused why it was hapenning. here is my code for my character control:
public class MyCharacterControl : MonoBehaviour
{
private Vector3 moveDirection = Vector3.zero;
public float Speed = 10f;
public float JumpSpeed = 40f;
public float Gravity = 40f;
public float PlayerRotationRight = 80f;
public float PlayerRotationLeft = -80f;
// Update is called once per frame
void Update () {
CharacterController control = GetComponent();
if (control.isGrounded)
{
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= Speed;
if (Input.GetKey(KeyCode.D))
{
transform.Rotate(0, PlayerRotationRight * Time.deltaTime, 0);
}
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(0, PlayerRotationLeft * Time.deltaTime, 0);
}
}
moveDirection.y -= Gravity * Time.deltaTime;
control.Move(moveDirection * Time.deltaTime);
//ANIMATION TESTING ONLY
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.DownArrow))
{
animation.CrossFade("01_Basic Run");
}
else
{
animation.CrossFade("Idle_01");
}
} }
Here is my camera smooth follow to player:
public class CameraFollow : MonoBehaviour
{
public Transform Player;
public int Distance = 0;
public int CameraVertical = 0;
public float CameraSmootFollow = 0.08f;
private Transform playerCamera;
private bool cameraSetup = false;
private string buttonText = "";
private Vector3 CameraDistance = Vector3.zero;
void Start()
{
playerCamera = transform;
}
void Update ()
{
if (CameraSmootFollow >= 1)
{
CameraSmootFollow = 1;
}
else if(CameraSmootFollow <= 0)
{
CameraSmootFollow = 0;
}
playerCamera.transform.LookAt(Player);
CameraDistance = new Vector3(Player.transform.position.x, Player.transform.position.y + Distance + CameraVertical, Player.transform.position.z - Distance);
playerCamera.transform.position = Vector3.Lerp(playerCamera.transform.position, CameraDistance, CameraSmootFollow);
} }
It's probably from mesh overlap. Can we get a screenshot of the flickering? Or is it literally turning the mesh on and off?
The camera transform should probably be in lateupdate. Don't know if that will help though.
Your answer
Follow this Question
Related Questions
default reference missing in prefabs 0 Answers
Cloud recognition in Vuforia 0 Answers
2D object flickers when it is in high speed in Unity 4.3 0 Answers
2D object flickers on moving Unity 4.3 2 Answers