Flappy Bird Style - Scrolling Repeating Background UI [7/10] Live 2016/12/19

preview_player
Показать описание
Watch this video in context on the official Unity learn pages -

In this beginner-friendly live training, we will look at creating a simple 2D Flappy Bird style game. We will cover best practices for infinite or endless games, basic object pooling and creating cartoon physics effects.
Рекомендации по теме
Комментарии
Автор

For anyone having issues with the scenery not lining up... the script is getting the size of the box collider attached to the ground objects. If the box colliders are wider than the ground objects, you're going to experience gaps in scenery. Resize your colliders to be the same width as the ground objects.

dahautam
Автор

3:57 when he said "don't forget to put 'f' at suffix that means float", is a complicated reason for who curious about that.
The answer why the suffix has "f" as float but it has Declared on first because at default c# will compile number containing a decimal point that doesn't have a suffix is interpreted as a "double" data type.

dwikilazzaro
Автор

if camera is not scrolling smoothly, check your "Main Camera" Component Camera.Size attribute. It should start from your beginning of scene which was not in my case and that was the problem.

cemalonder
Автор

My background doesn't move, all my settings are the same as yours and I copied and pasted your script into mine, was there an update since this came out that changed something?

Charles-fkeb
Автор

When I have my camera at a size of 5, it is too long for the backgrounds, so when i implemented Repeating Background, when it repeats it goes back past the scenery. I opened up the completed project in a separate project, and it had the same issue there. Clearly there is something up with my settings. The only thing that seemed to fix it was changing the size (zoom) of the camera to about 3.9. However, this is not preferable because I'm losing a lot of the height of the scenery. Futzing with the viewport rect cut off the right hand side of the scenery. Adjusting the scale of the camera seems to do nothing. My settings on the camera are as follows:
Position 0, 0, -10
Rotation: 0, 0, 0
Scale: 1, 1, 1
Clear Flags: Skybox
Background: Default Blue
Culling Mask: Everything
Projection: Orthographic
Size: 3.9 (adjusted to fit)
Clipping Planes:
Near: 0.3
Far: 1000
Viewport Rect: X=0, Y=0, W=1, H=1
Depth: -1
Rendering Path: Use Graphics Settings
Target Texture: None
Occlusion, HDR and MSAA are all checked
Target Display: Display 1

lindseyscruggs
Автор

Had an issue with the seams flickering when the two background just meet, I pushed it in 2px to solve the flicker issue

browsermage
Автор

How to increase the scrolling speed of the background in every frame?

vishalkhanna
Автор

When I push the mouse button, it, instead of pushing my character up,   restarts the scene from the beginning. What can be the problem?

stanislavvakulich
Автор

Seems like it would be a lot easier / more efficient to just scroll the background using a shader and updating position offset on the texture rather than moving 2 physical objects? Or do are sprites not loaded as mirrored textures?

hexcrown
Автор

If anyone else is having the issues mentioned previously, which seem to be caused by the previous "ground" object being destroyed just a little to early, therefore briefly exposing a portion of the base blue scene background (noticed at the left side of your game window when your next ground object is created) ...

I was able to fix it using the following method... (I am only just starting to learn development myself so all of this may not be correct. After trying multiple different fixes, this however worked instantly.)

1. Adding a 3rd "ground" object duplicate with exact same properties.
2. Placing the object at the end of the 2 current "ground" objects to create a seamless string of 3 objects.
3. Centering the main camera to start on the middle of the 3 objects.
4. Adding the following to my RepeatingBackground script.

void Update () {

if (transform.position.x < 2 * - groundHorizontalLength) {

RepositionBackground ();
}

}

private void RepositionBackground() {

Vector2 groundoffset = new Vector2 (70.62f, 0);
transform.position = (Vector2)transform.position + groundoffset;
}



This seems to always leave an extra "ground" object at the back potion of the camera when destroying an old object to create the new. This also works with the camera aspect ratio set to free aspect for a wider view.

tristanarnold
Автор

worked perfectly when i made little changes...awesome tutorial <3

muhammadawais
Автор

I made it such that the bird flies right to left. But no matter what I do the background won't repeat what should I do?
void Update()
{
if (transform.position.x > groundHorizontalLength)
repositionBackground();
}
Is changing this sufficient? or does somewhere else need to be changed too?

subhadeepmandal
Автор

in ScrollingObject's Start method, it had a statement:"rb2d.velocity = new Vector2(GameControl.instance.scrollSpeed, 0);", but in the first turn, the second ground didn't move. And when ''game over" then replay, everything was ok. I see that if i change the ""rb2d.velocity = new Vector2(GameControl.instance.scrollSpeed, 0);"to "rb2d.velocity = new Vector2(-1.5f, 0);", everything is perfect. T thought that when second ground calls GameControl.instance, it by some way destroys the ''instance", so it cannt scroll. But when gameover then replay, " SceneManager.LoadScene()" again and everything is ok. So can you explain this?? Tks!

huyphamle
Автор

I am getting Z fighting with my background, not quite sure how to fix it, is it because my box is 20.48 and the repeatingbackground is rounding so i get them too close, it's just a small blink but it's still visual enough to be annoying

hamiltonfergus
Автор

hey, why the background scrolling vertical instead of horizontal ?

testtestart
Автор

Changing scrollSpeed doesn`t have any effect. Why?

alexspec
Автор

i have this problem in unity console

NullReferenceException: Object reference not set to an instance of an object
ScrollingObject.Start () (at

any one can help me

graphicsstudio
Автор

Repeating backgrounds isn’t repeating, i’ve tried everything but it just doesn’t work. Any suggestions please?

tortellini
Автор

what happens when the offset reaches beyond a long long?

majidarifs
Автор

Error of this type: Groundoffset does not exist in the current context.

chandreshmendapara