Forum rules - please read before posting.

'Walking' on Parallax2D layer

Hey all, first time poster and first time Adventure Creator user!

I'm working on a 2D project, the set up of one of my scenes is as follows:
  • I have a foreground (in front of a lake) that is walkable.
  • I have a background (behind the lake) that is walkable.
  • I'm applying a small parallax (via Parallax2D) to the background, just to increase this sense of depth.

It works great when walking on the foreground, unfortunately when walking on the background (where this parallax is applied) the character slides - the parallax is not being applied to the character's movement.

Being a short time user, it occurs to me to expect this to be controllable via sorting layers, as in, when you're at x depth/layer, take on that layer's properties, but it doesn't seem possible.

For now I've added triggers and am attempting to parent the player to the layer art - is there a less hacky solution? I can't imagine I'm the first to attempt this.

Thanks Chris for the great tool, and everyone for your time.

Comments

  • Welcome to the forum, @dll.

    Well, actually, you may well be the first to attempt this - certainly the first to mention doing so here.  The Parallax2D component is actually only intended for scenery - not for moving the area that the player can actually walk on.

    As all the Parallax2D component does is change the object's position, it's theoretically possible that you could apply it to the ground sprite - though you'd also have to add this to your NavMesh as well, so that it too moves in sync with the ground.

    The difficulty would be in having only part of the NavMesh (background) move according to the Parallax2D script, while leaving the foreground alone.  Again, as this is not officially what it's for, I can't guarantee it working, but you could try creating two NavMeshes (one foreground, one background), so that you can safely apply the Parallax2D to one and not the other.

    The problem, however, would be that the NavMeshes would no longer be connected due to their being separate objects (and AC requires only one NavMesh active at a time).  In this case, you'd probably need to rely on Cutscenes any time you want the player to move between the foreground and background layers - so that you can control which NavMesh is active, and have the player move along a pre-determined Path to avoid pathfinding errors.

    The other solution would involve custom scripting.  I don't know how experienced you are, but the Parallax2D component could be duplicated and amended to control an attached PolygonCollider2D's vertices, rather than simply transforming the gameobject.  This could probably be used to control e.g. the background vertices of a single NavMesh to dynamically change it at runtime.  It'd be difficult, but could give better results and wouldn't need discrete Cutscenes when moving back and forth.
  • Thanks for the thoughtful reply Chris. 

    So far I've gotten by without having to overcome the navmesh issues, just by luck of having a bit of wiggle room in the art - but the tip for using a Cutscene and controlling the active navmesh is a good one.
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.