Pls help to fix laggy movement!

Updated on February 27, 2020 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on February 21, 2020

I decided to learn how to program games on unity by making my first ever project on ios. Unfortunately, I realised that my player has a laggy movement once I try to test my game. Could you please help me solve the problem.

Code (CSharp):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
public Rigidbody Rb;
public float speed = 5000f;

void Awake()
Rb = GetComponent();
// Update is called once per frame
void Main()
Screen.sleepTimeout = SleepTimeout.NeverSleep;

void FixedUpdate()
transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
Rb.AddForce(0,0,2000* Time.deltaTime);



  • Liked by
0 on February 27, 2020

It’s probably because you’re doing everything in FixedUpdate.

FixedUpdate only runs like every 12th frame (0.2s), so changing your input wont happen until the next physics cycle. Your physics are fine there, that’s what FixedUpdate is for, but all your Inputs should be done in Update.


Also, I think you’re missing somethings for your GetComponent. Maybe you can do it like that, but I’ve  only ever seen it like

Rb = GetComponent<RigidBody>();

Maybe you can do it without giving it a type though.

  • Liked by