How Do I Move My Character From Node To Node?

Discussion in 'How Can I...?' started by DocQ, Nov 10, 2020.

  1. DocQ

    DocQ Boxer

    Joined:
    Nov 9, 2020
    Messages:
    5
    Likes Received:
    1
    I'm trying to figure out how to move my character from one object to another with each tap of the screen. Any ideas on how to do this? Thanks in advance.
     
  2. Josh (Nology Games)

    Josh (Nology Games) Avid Boxer

    Joined:
    Nov 27, 2017
    Messages:
    200
    Likes Received:
    155
    Could you please give a detailed example? from the information provided, all I can say is to use a position animation node.
     
    DocQ likes this.
  3. DocQ

    DocQ Boxer

    Joined:
    Nov 9, 2020
    Messages:
    5
    Likes Received:
    1
    Thanks Josh. Please see the example provided below.

    With a tap to the screen, I would like to move my character (blue dot) to node 'A' at a predefined speed in a linear manner. A second tap would move the blue dot to the next closest node which is node 'B'. Lastly, another tap moves the character to node 'C' and so forth.

    Just want to see if this is possible. Thanks.

    upload_2020-11-10_22-55-8.png
     
  4. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    To achieve this you will need to do the following:
    - get the list of the points that you need to go to
    - sort that list based on distance from the initial location
    - get the first element and trigger an animation node from your point to that point
    - increment the next position
    - repeat the above
     
  5. DocQ

    DocQ Boxer

    Joined:
    Nov 9, 2020
    Messages:
    5
    Likes Received:
    1
    Thanks so much Vlad! Your solution works however, it will be quite tedious for me to set up the movements considering I will have hundreds or thousands of points in my game. Is there a way to have the character move to the next closest node wherever it may be on the screen?

    For example, my character initially starts out in a position where point A is closest so it would move there first. Then on the next tap, it would move to B as it becomes the closest to character.
     
  6. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    For the above you may do the following:
    - Add a if collider that collides only with your possible points
    - Increase the size of that collider based on your expected ranged
    - Add entities and remove them based on collider value If true add them to an array list otherwise shift the first element out
    - When tapped sort the list and get the nearest point (exclude the first one since that might be the current point)
    - Get the position of the next point and animate to that point
    - repeat the top selection based on your click
     
    Josh (Nology Games) likes this.
  7. DocQ

    DocQ Boxer

    Joined:
    Nov 9, 2020
    Messages:
    5
    Likes Received:
    1
    Thanks Vlad. Sorry, I have a beginner question as I'm new to Buildbox and don't know how to code.

    Am I required to update the code in order to do the last 4 steps of your instructions? I can't seem to find array list and sort functionality within Buildbox.

    Below are the steps I'm not sure:
    - Add entities and remove them based on collider value If true add them to an array list otherwise shift the first element out.
    - When tapped sort the list and get the nearest point (exclude the first one since that might be the current point).
    - Get the position of the next point and animate to that point.
    - repeat the top selection based on your click

    Thanks for your assistance. Much appreciated!
     
  8. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    I'm off for few days so I can't help you at this point. Just give it a try maybe you will find the way to do it without me/or until I come back to my pc

    Here is some code snippet that might help you with this

    let list = [] ;

    list.push(sender.collisionEntity());
    list.shift();
     
    DocQ likes this.
  9. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    Last edited: Nov 16, 2020
    DocQ likes this.
  10. DocQ

    DocQ Boxer

    Joined:
    Nov 9, 2020
    Messages:
    5
    Likes Received:
    1
    Hi Vlad!

    Hope you're feeling better now. Just want to say thanks for all your help. It's exactly what I was looking for. :)
     
    Vlad-NY likes this.
  11. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    604
    Likes Received:
    360
    I'm fine now, thanks for the good thoughts. This wouldn't be possible if you did not shared your thoughts with us.
     

Share This Page