Horrible lag in 2d roguelike character movement

I’m using a modified version of the game from the 2d Roguelike Tutorial . I’ve made only slight modifications to the original scripts. I’ve mainly added new UI elements and scripts to handle those UI elements.

I’m having issues with character movement. In the editor, the characters will mostly move fine, but when I build, all of the characters move, VERY slowly. It takes roughly two full seconds for a character to move into position. Everything else seems to run at full speed, but the cpu usage in the build is much higher than in the editor.

Also, even in the editor, there are still sometimes issues with the player character kind of weaving around and not staying square on a tile, so that if you walk by food it will pick up food on both tiles, etc.

I don’t know why any of this happening. There doesn’t seem to be any bugs in my code that would cause this, and I don’t know why movement would be so much slower in the build rather than the editor, or why cpu usage would jump. Any ideas about what might be causing this?

- YouTube here’s an example of the slow movement in the build. The character also doesn’t seem to always stay within the bounds of the tiles and weaves just as it did in the editor, only much slower.

and here’s an example of the the weaving the player does in the editor.

The character also glides from position to position without stop when holding the button down. And when checking the completed project today, the character seems to stop briefly before going on to the next tile when the button is held down. This behavior seems somewhat random, because even with nothing changed, the player will sometimes move normally.

You can see more about the project at http://www.fragmentalstew.com/

This is a demonstration of the game:

The license of the Roguelike tutorial prevents me from redistributing the project, but I may be able to give you access to to the project if you message or email me.

Here is a link to download the debug build

I am encountering the same problem in the editor even when running the fresh out the box “completed project”.
(like stated above, when built/ran it seems to run fine)


I believe rb2D.MovePosition(newPostion) in the SmoothMovement function in MovingObject seems to be the problem. The position doesnt seem to be updated every time SmoothMovement is called.
based on the docs, it says that the ‘actual position change will only occur during the next physics update’. Is it possible that the physics update isnt happening every call when ran in the editor?


I fixed this by changing

rb2D.MovePosition(newPostion);

to

rb2D.transform.position=newPostion;

Hello FragMental,

I had the exact same issue tonight while reaching the step 11 of the tutorial.
I tried to build the game for windows and my unity stoped working.
I killed the process and launched a new instance of unity.

The only loss I had in the process was my “Main Camera” parameters and the Player who disapeared from my hierarchy. I linked back my GameManager prefabs to the Main Camera and put my Player prebad in the hierarchi and here we go, problem solved.

The only one advise I could give you is to try to create a new scene, remake the steps I did and try.

So, I was trying to figure out what was wrong with the completed folder in my project, because it wasn’t working right. I had changed the name of a script and made a few changes, then copied the original script back but forgot to change a reference. So I changed the reference, and the completed scene still had issues with movement. So I tried copying an unaltered version of the completed folder over, and every time I did, that reference reset itself, which made no sense since the prefab with the reference was coming from the completed folder I was copying over.

I have a question about it here:
http://answers.unity3d.com/questions/1096799/copying-assets-from-one-project-to-another-creates.html

This made me think there could be something wrong with my project. I’ve been working on the project for 6 months or more and in that time I’ve had some computer crashes and unity crashes and other issues. So I exported my modified version, copied over the TagManager.Asset file, created a new project and then imported it in. This seems to have fixed the movement issue!

I have no idea what the cause was or if there was any other way to fix it. It may have even had something to do with the Unity upgrades I installed since I started. I have no idea. Either way it seems to be working now. After the export, there was a problem with lines across the board map but it seems to have resolved itself on its own.

Thanks @o-super, you helped me find a solution to this. At first I thought it had something to do with the massive changes I had made in the project, but we both seemed to experience the same issue. I think it was just some sort of buggy weirdness.

Hey everyone,


I know it’s been years but I thought I’d leave my experiences here for any future dwellers.


Basically I had a similar issue as stated by @Fragmental where my character would move super slowly (about 3 seconds per step), and if I input move commands while moving, the character would then do the aforementioned “weaving”.


I downloaded a run time Log Viewer by Dream Makers Group to dive into what was really going on.


So basically what I found was that the game was running at 600 fps. It was running at 600 fps as a result of selecting the build option ‘Fastest’ when building the game. Not sure why that happens though. Anyway, setting the build options to ‘Beautiful’ made the game run at 60fps, and then everything worked fine.


The reason why things didn’t work as well at 600 fps can be described by the following post: https://answers.unity.com/questions/10993/whats-the-difference-between-update-and-fixedupdat.html?_ga=2.82499414.1351522315.1569119747-984558385.1533734503


If you ever stumble across this, do try this solution :slight_smile:
And go Unity! You guys rock.

The cause of the problem is the FPS going too high during the build. To fix it, create a new script called TargetFrameRate and attach it to your GameManager prefab:

TargetFrameRate.cs

using UnityEngine;
using System.Collections;

public class TargetFrameRate : MonoBehaviour {
    
    public int target = 60;
    
    void Start()
    {
        QualitySettings.vSyncCount = 0;
    }

    void Update()
    {
        if (target != Application.targetFrameRate)
        {
            Application.targetFrameRate = target;
        }
    }
}

This will basically force the application into 60fps, resulting in smooth scrolling. Hopefully this can be marked as the correct answer @Fragmental.

Was working on this tutorial just now and ran into this exact problem while on step 11. I don’t know if this may be the case for some people, but when testing in the editor, the player started weaving (like aforementioned). But, when I built the project, the build ran just fine, with the player staying on the tiles as normal. I suspect a problem may be processor speed/memory allocation, as I was working on a laptop with modest specs.