Movement speed different on different computers?

I’ve been trying to make a movement equation without much luck. I might just be over complicating it, but I’m not sure why it’s not working. On my brother’s computer, it runs much too slow (His computer is wicked fast.). And on mine, it runs just right.
Here’s my movement equation that I’ve got. Any criticism is also welcome.

public void move(int delta){
		xCollision = false;
		yCollision = false;
		pastX = x;
		pastY = y;
		velocity.y += (G_ACCELERATION * delta)/1000.0;
		x += (velocity.x * delta)/1000.0;
		collisionBox = new CollisionBox(x, y, sprite.getWidth(),sprite.getHeight());
		if(doesCollideOnX()){
			x = pastX;
			velocity.x = 0.0; 
			xCollision = true;
		}
		y += (velocity.y * delta)/1000.0;
		collisionBox = new CollisionBox(x, y, sprite.getWidth(),sprite.getHeight());
		if(doesCollideOnY()){
			y = pastY;
			velocity.y = 0.0;
			yCollision = true;
		}
		collisionBox = new CollisionBox(x, y, sprite.getWidth(),sprite.getHeight());
	}

If it helps any, the main specs on my computer are 2.1ghz Core 2 duo CPU, 4gb RAM, and 256mb on board video memory.

You need to keep a constant frame rate. I see delta in there somewhere, are you using delta timing?

Yeah, i’m using delta timing.

Maybe his computer runs so fast that the program reads delta as “0”.

EDIT: A quick “System.out.println(delta);” will show.

EDIT2: Ah I read too fast, sorry.

Well, it does move, and i’ve monitored the delta as 1 on his computer.

Probably a rounding-error somewhere, or you haven’t capped your deltaTime.

I cannot say that I’ve capped my deltaTime. What do you suggest would be a good cap?

Depends. Are you using libgdx or some other library? If so, you shouldn’t have these problems, and you shouldn’t need to implement a cap. deltaTime should probably not be 1. It should be a float. My deltaTime, using libgdx is something like 0.000165532564577 (taken from memory, not an actual case). Which deltaTime do you get on your own computer vs his?

Well, I’m using my own engine, and all the delta is measured in milliseconds. For his computer, he gets 1ms as his delta. I usually get around 5ms on mine.

Please yield code snippet where you calculate deltaTime and apply it to something.

It seems like you did not do serious debugging. The problem is most likely your game loop, but we can only make wild guesses at what the problem might be.

Note that if you have a delta of 1.999 milliseconds that scraps the remainder after rounding, then you will not have consistent movement and will move slower at that rate than 1.000000001 rounded to 1.

Velocity movement with deltas is complicated.

It means that if loop A runs twice as fast as loop B, and the velocity increment is 0.5.

loop A delta = 1
loop B delta = 2

tick 1
A speed = 0.5 dist = 0.5
B speed = 1.0 dist = 2.0

tick 2 (still tick 1 for loop B)
A speed = 1.0 dist = 1.5
B speed = 1.0 dist = 2.0

tick 3 (tick 2 for loop B)
A speed = 1.5 dist = 3.0
B speed = 2.0 dist = 6.0

etc.

You need to work out a way to fix this or switch to a fixed timestep.

That’s what I’ve been trying to do, and that’s the reason I posted here.

As for the game loop, you’ll probably all think it to be atrocious, but here you go, copy and pasted straight from my engine.

log("Starting Toasted Engine...");
		boolean successfulShutdown = true;
		Screen.setTransform(backupTransform);
		long lastTime = System.nanoTime();
		double unprocessedSecond = 0;
		int frames = 0;
		boolean ticked = false;
		
		splashTimer.start();
		while (running) {
			long currentTime = System.nanoTime();
			long deltaTime = currentTime - lastTime;
			lastTime = currentTime;
			unprocessedSecond += deltaTime / 1000000000.0;
			while (unprocessedSecond > secondsPerTick) {

				unprocessedSecond -= secondsPerTick;
				ticked = true;
				tickCount++;
				if (tickCount % 60 == 0) {
					FPS = frames;
					lastTime += 1000;
					frames = 0;
					if (printFPS)
						log(Integer.toString(FPS));
				}

			}

			if (ticked) {
				delta = (int) (deltaTime / 1000000);
				if(!splashTimer.isDone() && showCustomStaticSplash){
					splash(delta);
					Screen.add(customStaticSplash, 0, 0, Screen.getScreenWidth(), Screen.getScreenHeight());
					Screen.drawToWindow();
					continue;
				}
				if(updateTimers)
					for (Timer t : timers)
						t.update(delta);
				for (EngineLoop el : methods)
					el.doProcesses(delta);
				AffineTransform preRender = Screen.getGraphicalTransform();
				for (RenderLoop rl : renderLoops){
					rl.render();
					Screen.setTransform(preRender);
				}
				if (renderDebug) {
					Font.RenderText("FPS:" + FPS, 0, 0, 1, debugColor);
					Font.RenderText("Delta:" + delta, 0,Font.getCharHeight() + 2, 1, debugColor);
					Font.RenderText("Tick:" + tickCount, 0,	2 * (Font.getCharHeight() + 2), 1, debugColor);
					Font.RenderText("Render loops:" + renderLoops.size(), 0,3 * (Font.getCharHeight() + 2), 1,debugColor);
					Font.RenderText("Logic loops:" + methods.size(), 0,4 * (Font.getCharHeight() + 2), 1,debugColor);
					Font.RenderText("Timers:" + timers.size(), 0, 5 * (Font.getCharHeight() + 2),1, debugColor);
				}
				frames++;
				Screen.drawToWindow();

				long timeTaken = System.currentTimeMillis();
				long sleepTime = period - timeTaken;
				try {
					Thread.sleep(sleepTime);
				} catch (Exception e) {
					
				}
			}

		}

Off the bat:
long lastTime = System.nanoTime();
should be changed to
long lastTime = 0;

Otherwise your first update will run with a deltaTime of 0.

These variables are weird. timeTaken is not actually set to the time taken to render the frame, and period is, for us, undefined. Please elaborate.

long timeTaken = System.currentTimeMillis();
long sleepTime = period - timeTaken;

I’ve been using this loop since I started programming, I got it from a youtube tutorial. I’m not quite sure of what’s going on there. I should probably just remove it

No no no, you have to sleep (or yield) between updates!

Yeah, idk what I was thinking. Btw, the period variable is equal to 30. At this point, I’m thinking I might need to rewrite my engine…

What is period set to? It seems to me, that you’d have to change
long timeTaken = System.currentTimeMillis();
to
long timeTaken = System.currentTimeMillis()-lastTime;

But I don’t think this’ll help your problem.

You can easily implement another gameLoop, without having to change all your update-code. I do think you have to simplify/rethink your time-handling.