How do I got to the nearest vacant space?

0 favourites
  • 3 posts
From the Asset Store
Spaces Ambience contains 102 Sounds: 53 track and 49 sounds
  • So I have a striker who has a limited x axis to move along and also some pucks that if they overlap with my striker the striker should automatically move to the nearest empty space. One for reference. I am adding a video link.

    https://www.youtube.com/shorts/giNungtO-5w?feature=share

    thank you

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Looks beautiful!

    Save the puck x and y on a global variable.

    Then you can test if its overlapping when choosing a space.

    When puck stops. Save its x and y.

    Then set its location to the global variable x + its width.

    If its overlapping something, use the global variables to reset its position.

    Give it a variable count on fail.

    Then say if variable =1

    Reset position to global xy

    Move puckx to puck x - its width.

    You can then do this to its y axis. If it overlaps again

    This is.. 4 directional... 8 is you make more clauses

    Hope this helps. Hope I understood what you wanted

  • Think I mis understood.

    termanolagy I'm not 100% on

    You want the white puck to not overlap while choosing a place to use it from?

    So instead of going red, you want it to lock to the nearest available position? Until the mouse has taken it past a point.

    Say the blocking piece is 50 wide.

    On colision set the piece to have a boolean.

    When boolean is checked.

    While

    Boolean is true

    mouse x is between piece.x-25 and piece.x

    Set puck.x to piece x-50

    While

    Boolean is true

    mouse x is between piece x+25 and piece.x.

    Set puck to piece x+50

    I turned off the computer, cant test it untill tomorrow.

    But, that should activate a piece on contact. And set the puck location to next to the piece right or left, depending on the mouse location.

    Just have to turn off boolean when mouse goes past

    This will lead to more issues if 2 pieces are next to each other. I'll work on it tomorrow if that's what you need.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)