Forum rules - please read before posting.

Simple 2d character movement ONLY along the x-axis

edited August 2014 in Technical Q&A
Hi guys,

I want to implement a simple 2d character movement only along the x-axis, similar to the way Machinarium works.
So even if the player clicks along the y-axis, it will only take the x parameter and move my character along the x-axis only. No movement along the y-axis at all.

I still want it to be a point-n-click game controlled with the mouse.

Thank so  much for your help.

Comments

  • This is simple in Direct mode, but for Point and Click it's a bit more fiddly.  Assuming your in Unity 2D mode, try making your PolygonCollider very thin, vertically, so that the Player can only move left and right any noticeable amount.

    Occasionally your Player might still face up/down (e.g. when turning).  If you're using Unity Sprites as your animation engine, you'll have to assign left and right sprites for your up and down directions (e.g. Idle_L is the same sprite as Idle_U).

    On the other hand, Sprites Unity Complex can be used to give full control over your Player's Animation Controller.  You can limit animations to only left and right based on the "Direction" integer that AC outputs.
  • Thanks so much, Chris!

    I will try it out!
  • I have a similar problem. I have a long underground tunnel, and I want the character to move along it in a straight line. I have Sprites Unity Complex 2D and locking to a path thus doesn't work. I would like to be able to click on a general spot on the scene and the character to move as close to it on its designated path as possible, as described in the OP. I have a custom movement script made by you, Chris, which works great. But it allows the character movement only when I click the NavMesh (and I want to keep it that way in other levels) - so I cannot solve the problem by narrowing the NavMesh.

    Is there some easy solution to this? I was thinking about actually narrowing the NavMesh and creating a series of hotspots with a "walk to" function wider than the Navmesh that would substitute its function. But perhaps there is a better way?

  • A script to limit point-and-click movement to one axis is available on the AC wiki:

    https://adventure-creator.fandom.com/wiki/2D_point_and_click_along_one_axis

  • Works great, thanks!

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.