Search Unity

Waypoints

Discussion in 'Getting Started' started by DocJ, Dec 15, 2021.

  1. DocJ

    DocJ

    Joined:
    Dec 9, 2016
    Posts:
    98
    Sorry. Wrong thread. Please disregard




    Hi and thanks in advance for any guidance. I put this thread in Getting Started but it might not be the appropriate thread for this question.

    I'm not looking for anybody to script for me, but I have a question more or less to see if this problem is scriptable. I have not been able to find answers throughout my searches.

    Say for example a person is told to walk down a street for 6 "Blocks", turn right and the 2nd house on the side street is his destination.

    Each Block corner is identified by a waypoint. Each house on the side street would theoretically be identified by a "child waypoint" or a "branch" off the "Block" waypoint.

    Part 2 of the problem is if the player turns down the side street, say 2 Blocks too soon, but still goes the distance of the 2 houses. Can I get him back to the "Block" waypoints, counting the 5th Block as his starting point on his next turn ( since he turned too early)?

    In other words he is supposed to walk like this ( The numbers represent the Blocks, and the letters represent the houses on the side street):
    1 2 3 4 5 6 a b

    But instead walks like this:
    1 2 3 4 a b

    Can his next turn start like this?:
    5 6 a b (begin next turn at main waypoint where he took the "wrong turn")

    Thank you very much for taking the time to read this and help if you can.
     
    Last edited: Dec 15, 2021
  2. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    278
    Is this a linear checkpoint system? Because if it is, I'd just give those blocks a number (as you already did) and each time you enter a block, you save that number if it is higher then the number you already have stored.
     
  3. DocJ

    DocJ

    Joined:
    Dec 9, 2016
    Posts:
    98
    Thank you for responding. Being new to coding, I understand using waypoints to "guide" the player, but if I add "branching" waypoints to each "block", won't the player walk up each block and down each branch?
     
  4. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    278
    In the end it all comes down to how to store data, and then later use that data to do something. Normally you'd spawn the player at a checkpoint he already visited (in your example that would be 4) but you seem to want to advance the player (to block 5) when he makes a mistake, is that correct? Since you know the target is (inside of) block (6) you could look at the last visited block (4), and add 1 to that number as long as it is below 6. Since the checkpoints are "block" bases and not "house" based we can ignore the houses.

    Think like this: as long as your player is actually playing, you should update a bit of data every time a waypoint is reached. From this data, you should be able to determine a new spawn point when appropriate. If they are linear, all you have to remember is a number. If they are branching, then there exists some branching structure in your game that already that defines this. You'd need of a way to store some data seperately from this structure, that is enough to somehow find it's way back.

    Or perhaps, you could save some x-y-z position every time a waypoint is activated. Then it no longer matters how your waypoints look. Is it absolutely vital we know what waypoint that is, or is a position enough information to respawn the player?