Forum rules - please read before posting.

Limit 2D movement to left/right

I have read earlier threads where people asked if it was possible to limit a 2D characters movement to the left/right axis (i.e. to create a side-scrolling platformer-ish movement) while still using a point and click mouse interface, and I know that it's not possible within AC. I also know that the best way to achieve something close within AC is to make the navmesh extremely narrow.

However, I thought I'd ask again to check if there had been any updates/new features that somehow allow this? And if not, @ChrisIceBox do you think it would be possible to restrict the character to the left/right axis with some not-too-large script, and if you can think of a way could you give some general pointers as to how it might be achieved?

Comments

  • edited November 2018
    Well, I just wrote this small script to be attached to the Player:

    But I'm not sure if this solution will be problematic in some way regarding playing the correct Player animations? Besides, if I click much above or below the x axis of the Player, his movement gets slower (I guess that's because he's trying to move on the y axis). Perhaps someone has an idea for how to tweak it to make it work?

    EDIT: Okay, I just discovered that if I click much above or below the x axis, the Player keeps walking in place, because he's not able to reach the y coordinate.
  • Indeed: you're still commanding the player to move along the Y-axis, but preventing him from doing so.

    What you want to do is have a script that calls the Player's MoveToPoint function manually, using the cursor's X position and player's Y position.

    Try this:

    To use it, keep the Movement method set to None, but use the Engine: Manage systems Action to set Movement to Disabled in your OnStart cutscene.

  • Ah yes, I'm going to test it later, but from the looks of it, that script seems like it should do exactly what I'm looking for. Thank you!
  • edited November 2018
    I tested the script now, and it works perfectly :)

    I take it that it was a blunder when you wrote 'keep the Movement method set to None', right? Anyway I set it to Point and click, and it's working as it should.

    EDIT: By the way, I was looking for the Engine: Manage systems Action in the scripting manual, but I wasn't able to find it. Is it possible to run that action from script, so I can just put in void Start() in the script, instead of having to run it from a cutscene in each scene?
  • I take it that it was a blunder when you wrote 'keep the Movement method set to None', right?

    Where did I write that?

    By the way, I was looking for the Engine: Manage systems Action in the scripting manual, but I wasn't able to find it.

    All Actions are described in the "Standard Actions" chapter.

    Is it possible to run that action from script, so I can just put in void Start() in the script, instead of having to run it from a cutscene in each scene?

    The effects of the will survive scene changes - you only have to put it in your first scene, or alternatively your "ActionList on start game" asset.  To perform this change through script, however, you call:


  • Thanks for the elaboration.

    I'm not sure if this is because I missed something - but to restrict the player from walking to certain points on the x axis I'm still using a navmesh and then ticking 'Do Pathfinding' on the script. But when he walks to the edges of the navmesh, the pathfinding causes him to move slightly up or down on the y axis. Do you think there is a way to avoid this?
  • Certain points such as what, the hard left/right limits?

    That can be coded into the script - see the entry in the wiki I wrote.
  • Yes, the left/right limits of the navmesh.

    Thank you for the updated script! I'll just remove my navmesh and use that instead :)
  • edited July 2020

    @ChrisIceBox
    I've encountered a problem with this navigation method. Initially it's working fine, but if I have a hotspot set to "player action = walk to marker", the player walks on the Y axis. Which is strange actually, since the marker is placed on the same Y coordinate as the player.
    Afterwards the player is stuck on the new Y value.

    Here is a video showing the problem: https://www.loom.com/share/aa835b26981b429da71d26691ab7baaa

    EDIT: On further inspection, it seems that the player doesn't really walk to the marker at all, since if I put the marker in an entirely different place, the player still walks to above the hotspot - only a slightly different position.

    2nd EDIT: Also, if I have two hotspots with a walk-to marker each, the player still walks to almost the same position, no matter which hotspot I click, so the position might not even be related to the position of the hotspot.

  • edited July 2020

    I've updated the script to account for hovering over a Hotspot - grab it again and see if the issue remains.

    If so, what is the effect of removing the script from the scene, so far as clicking such Hotspots go?

  • Ah, you know what, I was just going to say, that the updated script made no difference, but then when checking the effect of removing the script, and the result was still the same, it dawned on me.

    The problem was that my navmesh was still just the standard pentagon in the middle of the screen, so that's the spot the player was walking to.

    I didn't realize that I still needed the navmesh for this navigation method. Now I've just extended the navmesh to fill the entirety of the screen, and it seems to be working perfectly :blush:

    Thanks for the help!

  • Yes, the script only affects gameplay clicks - not the character's behaviour when moving automatically, i.e. towards pre-set Markers.

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.