- Home /
2d Top Down Shooter Jerky Movement
Hey guys I am a newbie in unity. Currently I am making a 2d top down shooter based game. And here comes the bug. So character movements I am using Brackeys top down shooting tutorial. And here is the code.
using System.Collections;
using System.Collections.Generic; using UnityEngine; public class PlayerMovement :MonoBehaviour
{
[SerializeField]private float movementSpeed = 5f;
[SerializeField]private Camera cam;
private Rigidbody2D playerRb;
private Vector2 movmentVector;
private Vector2 mosusePos;
private Vector2 lookDirectionVec; //Start Called once private void Start() { playerRb = gameObject.GetComponent<RigidBody2D>(); } //Update Called Every Frame private void Update() { GetingInput(); MouseRotation(); } //Fixed Update private void FixedUpdate() { playerRb.MovePosition(playerRb.position + movmentVector * Time.fixedDeltaTime); // playerRb.velocity = new Vector2(movmentVector.x, movmentVector.y); } private void GetingInput() { Vector2 inputVector = new Vector2(Input.GetAxisRaw("Horizontal"),Input.GetAxisRaw("Vertical")); movmentVector = inputVector.normalized *movementSpeed; lookDirectionVec = cam.ScreenToWorldPoint(Input.mousePosition) - transform.position; } private void MouseRotation() { float angleToRotate = Mathf.Atan2(lookDirectionVec.y,lookDirectionVec.x) * Mathf.Rad2Deg - 90f; Quaternion qRotation = Quaternion.AngleAxis(angleToRotate,Vector3.forward); transform.rotation = qRotation; }
}
But whenever I test the game the movements are jittering. Like the shutter the movement. I found some solutions on web articles and unity forms. The first I tried is to change RigidBody2d.MovePositions() to RigidBody2d.Velocity but the result is also the same and the second one is to change the camera size 5 to 10. Second one is kind of a work but it stills jittering. So any solutions to this. Here are the camera properties and player properties.
Your answer
Follow this Question
Related Questions
2D Grappling Hook problems 0 Answers
2D Top Down Shooting Problem 1 Answer
2D Wall Jump and Wall Friction 0 Answers
How do I set direction of player dash movement? Currently dashes to exact mouse position. 2 Answers
How do I add force to a RigidBody2D? 2 Answers