Forum rules - please read before posting.

AC Scrolling 2D Background

What is the process for having a background scroll left while the player is running in place?

Comments

  • Welcome to the community, @cparker101.

    The general behaviour is for a Player to move while the background remains constant.

    If you wanted the Player to remain in the same position on-screen as they move, the easiest approach would be to have the GameCamera2D that follows them to have a very high "Follow speed" value so that it doesn't lag behind the Player as they move.

    Or are you looking for the Player to physically keep their position constant, and the background elements actually move instead? If it was in a cutscene, you could use Timeline to animate all these elements (including the Player) together, but if it's in gameplay you're probably looking at some scripting.

    If you can elaborate more on your exact needs, I can try to offer more specific advice.

  • Thanks for the super quick response.

    I am looking for the Player to stay in place with a Running animation, but have the background, which will consist of two images side-by-side, constantly move left, swapping images when the image width has reached it's actual length. Or, in other words, make it appear that the player runs as long as the game is is play.

    Hope I explained it better ...

  • So, this would be going on during gameplay, as opposed to just during a cutscene?

    If so, it's best to tackle them separately. The scrolling background can be handled by animation - no need to involve AC specifically.

    Parent one of the background sprites to the other, attach an Animator to the same parent, and then create a looping Animation that has them scrolling. So long as this animation is the default one in the Animator Controller, it'll play by default and won't need to be referenced/controlled by AC.

    See Unity's documentation for more on creating Animations and Unity's Animator component.

    For the Player - again, if this is going on the whole time - the easiest way is to simply have their "idle" animation depict them running, so that AC considers the Player motionless even though they appear to be moving.

    If this effect is intended only for a specific scene, make use of a local Player that only exists in this scene - that way, you can have them behave normally in other scenes, and this scene won't affect others.

    Drop your Player into the scene file, and make changes to have them play a running animation when idle. If they are only running in one direction, you can set their "Facing directions" field to "None", so that they only need a single idle animation, rather than one for each direction (north, east, south, etc).

    To prevent the Player from actually being able to move, use the Player: Constrain Action in your OnStart cutscene to disable their Movement ability.

  • Thanks so much for your help! Using a looping animation did the trick. Then I dropped a Player into the scene as you recommended. Works pretty well, except for a slight hiccup when the animation reaches the end and begins to loop back. I'll figure that out. Here's the result:

    https://parkerdevsite.com/ACScrollingDemo.mp4

  • except for a slight hiccup when the animation reaches the end and begins to loop back

    Probably just a case of setting the animation's interpolation to Linear, which you can do by selecting its keyframes in the Animation window and right-clicking.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.