- Home /
Question by
temichas_unity · Sep 14, 2021 at 04:41 PM ·
movementunity 2drigidbody2dstutter
Unity 2d RigidBody Movement stutter
Game stuttering on object movement.
Why does it stuttering? There are micro stutters. Always near 60 fps on Android device. Camera (cinemachine) folowing the object.
Scene:
This is movement script
using Cinemachine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hero_Script2 : MonoBehaviour
{
[SerializeField] private float Speed = 2f;
public Rigidbody2D HeroRB;
private Vector3 StartPos;
private void Start()
{
Application.targetFrameRate = 300;
StartPos = transform.position;
}
public void btnRestart_Clicked()
{
transform.position = StartPos;
}
private void FixedUpdate()
{
HeroRB.velocity = new Vector2(2f * 100f * Time.fixedDeltaTime, HeroRB.velocity.y);
}
}
Hero object:
Camera:
Comment
Note: I fixed your script formatting. If it doesn't look right in the post preview, it won't look right when posted, either.
Although this doesn't necessarily solve the problem at hand, the way you defined your velocity's not great. Rigidbody(and 2D).velocity is already a per-second rate and doesn't need to be multiplied by Time.(fixed)deltaTime, since this makes it framerate-dependent.
You can replace
2f * 100f * Time.fixedDeltaTime
with (most likely)
4f
for the same resulting speed.
(2 * 100 * 0.02) = (200 * 0.02) = (4)
Your answer
Follow this Question
Related Questions
In unity 2D c# how to rotate an object like geometry dash? 1 Answer
Stuttering/jerky movement of kinematic rigidbody 2d moving by velocity in 2D game on iOS 0 Answers
Colliding players spin out of control and rotation is local. Need help! [C#] 0 Answers
How to Create a Launch Path? 2 Answers
How to give player a "dash" ability? 0 Answers