Question by
unity_129529 · Aug 03, 2020 at 08:20 AM ·
movement2d game2d-platformershaking
My character is shaking while walking. 2D game
I made a really simple 2D walking game, with custom created tilemaps / pixelart. But now when I walk with my character, it kind of shakes and blends in with the background. I started off simple with the movement, since I'm new to Unity development, but I got this problem quite early into making the game, does anyone know how to fix this?
This is my player movement code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rb;
public float Speed = 8f;
// Start is called before the first frame update
void Start()
{
Cursor.visible = false;
}
// Update is called once per frame
void LateUpdate()
{
if (Input.GetKey(KeyCode.A))
{
rb.velocity = new Vector2(-Speed, rb.velocity.y);
gameObject.GetComponent<SpriteRenderer>().flipX = true;
}
if (Input.GetKey(KeyCode.D))
{
rb.velocity = new Vector2(Speed, rb.velocity.y);
gameObject.GetComponent<SpriteRenderer>().flipX = false;
}
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, 20);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to cancel the force caused by collision? So the player is not pushed away when it hits a corner? 0 Answers
Unity 2D Enemy movement problems 2 Answers
How to create a movement script for my person by controlling him by joystick 0 Answers
Walk around square platform 0 Answers
Load a Scene and have the player be move to a specific location 1 Answer