• Create Account

# Magdev

Member Since 17 Nov 2012
Offline Last Active Oct 03 2013 04:01 AM

### In Topic: Player Jittering with Camera Follow

23 May 2013 - 08:50 AM

You have misunderstood my suggestion. Let suppose the player is moving 1 pixel in some direction. Since (playerPos - camPos)*strength is not related to the player movement, it can be any value. In particular, it may rounds to 2 pixels in the same direction. The result is the player moving one pixel in the wrong direction. In the next frame the player will move of 2 pixels and the camera of some other amount and you now see a jitter. The jitter is caused by the difference between the camera position and the player position not being a monotonic function. My suggestion is thus to make it monotonic by clamping the camera position so that it does not move faster than the player. When the player is still you clearly have to catch the player if you do not want the player to exit from the screen.

Ooh. I understand. Yeah, I'll definitely try that.

### In Topic: Player Jittering with Camera Follow

23 May 2013 - 08:34 AM

```if (camPos != playerPos) camPos += (playerPos - camPos) * strength;
```
This seems dodgy to me. What happens if the distance between player and camera is smaller than the length of (playerPos-camPos)*strength? This would happen if strength>1. You don't show how you calculate strength, so I assume it's tied to elapsed time somehow. If strength>1 then the camera will over-shoot the player's position which can possibly cause camera stutter. You might try clamping strength to 1 to keep it from overshooting.

Strength is just a constant between 0 and 1 that I define in-code which is just the strength that the camera follows the player. No time variable is needed.

The problem is in my opinion that the camera may sometimes need to move faster then the player to catch it.

That's not related to the jittering problem, but it can be a problem for some people. I don't see it as a problem though. I don't think it's even possible for the player to move fast enough to leave the camera's view, but if it is, it's not really a big deal. If it becomes an issue then I can just constrain it.

To some degree this is an inevitable consequence of the system you have. You're essentially rounding a real number to an integer and so you have an effective error of +/- 0.5 each time. This means the movement speed in pixels varies by up to one whole pixel from frame to frame, which means it's going to jump ahead and behind a camera moving at a continuous rate. Making the camera track the pixel position like I suggested may reduce the problem but, now I think about it more clearly, it can't solve it.

I think the only real solution is to be able to move both the entity and the camera with subpixel precision, or to lock the camera to the entity pixel position (rather than attempting to smoothly track it after it moves).

Yeah, it does seem like the nature of the system. I have a few workaround ideas in my head, but at the very least, the first fix did make it pretty acceptable and not very noticeable. The jittering how it is now is exactly like Cave Story's jittering, which is barely noticeable, which also reinforces how it's probably not worth fixing further. Thanks a lot for your help.

If I come across anything that makes it better, I'll post it in this thread.

### In Topic: Player Jittering with Camera Follow

23 May 2013 - 07:38 AM

The camera position code is in the first post.

### In Topic: Player Jittering with Camera Follow

23 May 2013 - 06:26 AM

You need to make your camera track the on-screen render position, not the logical position before rendering.

Ooh. That makes a lot of sense. I did what you said and it fixed the jittering during constant movement, but there's still jittering while the camera builds up to the player's speed.

I ran the game at 10% speed and output the camera's delta and position, holding a key to mark the jittering frames when I saw them.

It's not super accurate because of my timing, but it seems like it only jitters when the camera moving more than one pixel per frame. The player moves at a constant speed of 1.5. When the camera is at 1.5 delta, it alternates between one pixel per frame and 2. Not sure how helpful this information is.

I could possibly clamp the camera speed below 1, but that's probably too slow, and just a workaround rather than a fix.

Any ideas?

### In Topic: video game addiction?

29 December 2012 - 02:44 PM

I was really addicted to videogames in elementary school. I remember constantly pulling all-nighters on school nights to play Gunbound, Maplestory, Ragnarok Online, and Dark Ages. It was really unhealthy. I remember staying up for so long without leaving my chair, that when I went outside to check the mail I felt all woozy and confused from the light.

It pretty much continued all the way until high school. It wasn't as extreme, but I always had mediocre grades as a result. It's not all bad though, being on my computer as much as I possibly could opened me up to all types of genres of games, the indie game industry, and some forums which slowly brought me towards wanting to be a game developer.

I've been focused on working on my games so much lately, that I've only played a few of hours of videogames over the entirety of December. It feels pretty nice staying on track and productive.

PARTNERS