# manually scrolling by "depth" in 2d

This topic is 3991 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

im working on a sidescroller, orthogonal projection so no real depth. I want to place an object in the "background" and have it scroll from left to right slower than an object in the "foreground." Parallax scrolling. How can I manually calculate the position of an object in 2D based on a "depth" value that I determine? How do I figure out where to draw it so that it will scroll slower because its in the "background"?

##### Share on other sites
I wouldn't actually modify the position of the objects, because then you get into the problem of not knowing what the real position of something is versus its "fake" position you use to simulate parallax. And it doesn't really make sense to do so either, since objects don't have to physically move in order for them to appear to be moving at different speeds (i.e. when the camera is on motion).

Instead I would throw your objects into a pipeline of sorts that calculates view-space position based on world-space position. Since your project is a 2D side-scroller this should be rather simple. Usually there's a straightforward duality between camera translation and object translation, such that if your camera translates X units in one direction, it appears as though your objects translated X units in the opposite direction. With parallax, a camera translation of X units in one direction would correspond to an apparent object translation of X/(D+C) units in the other direction, where D is depth of the object and C is an arbitrary constant used to control the "initial condition", or how fast objects move at depth 0. So hopefully that clears some things up for you :)

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013612
×