- Home /
jittery jumping 2D character
I am trying to make a simple platformer but when my character jumps the character and the camera(which is attached to the player) jitter. Its very noticeable. First off I thought that it was because my animation sprite sheet was not the correct resolution(can't be bothered to fix this) but its not that because the camera is attached toe the player and thats jittering as well.
I really need some help with this, also my character can glitch into walls for 1 milli second and pops back out. Because of this my ground check doesn't work properly.
If anyone could tell me how to fix these problems i would be really thankful.
CODE:
using UnityEngine;
using System.Collections;
public class playerController : MonoBehaviour {
public GameObject camera;
public float speed = 4f;
bool grounded = false;
public Transform groundCheck;
float groundRadius =0.1f;
public LayerMask whatIsGround;
public float jumpForce = 4f;
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate ()
{
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
anim.SetBool ("ground", grounded);
anim.SetFloat ("speed", 0);
if(Input.GetKey(KeyCode.D))
{
transform.Translate(Vector2.right * speed);
transform.eulerAngles = new Vector2(0, 0);
camera.transform.eulerAngles = new Vector2(0, 0);
camera.transform.position = new Vector3(camera.transform.position.x,camera.transform.position.y,-15);
anim.SetFloat("speed", 1);
}
if(Input.GetKey(KeyCode.A))
{
transform.Translate(Vector2.right * speed);
transform.eulerAngles = new Vector2(0, 180);
camera.transform.eulerAngles = new Vector2(0, 0);
camera.transform.position = new Vector3(camera.transform.position.x,camera.transform.position.y,-15);
anim.SetFloat("speed", 1);
}
}
void Update()
{
if(grounded && Input.GetKeyDown(KeyCode.W))
{
rigidbody2D.AddForce(new Vector2(0, jumpForce));
}
}
}
Your answer
Follow this Question
Related Questions
animation 2d platformer 2 Answers
switching between different screen boxes 2 Answers
2D Buttons 1 Answer
Play two 2D animation together? 2 Answers