Movement in a grid, somewhat stuck

tuftyfellatuftyfella Member, BASIC Posts: 17
edited August 2016 in Working with GS (PC)

i have a grid of 48 (8x, 6y) actors which when pressed on fade in and out to show when + where pressed for the player.

what i want to do is move the hero actor from one location (grid actor) to another (grid actor) at 90 degree angles only, however im unsure of how to approach this.

so far ive put a constraint attribute for x + y positions on the grid actor and attached those to new game attributes (which i think is a start) then tried a 'Move To' behaviour pointing to those new game attributes. this doesnt even move the hero actor and also stops the fade in/ out pressing of the grid actors. im not sure how else i can move the hero actor from one grid actor to another.

ive looked at a few other touch to move tutorials and templates, however they dont include touching a specific actor to have another move to it and im not sure how i can adapt them to do this.

any help/ hints would be appreciated, thanks for reading. :)

Comments

  • NNterprisesNNterprises Member, PRO Posts: 387
    edited August 2016

    So you want it to move in straight lines only (not diagonal at all)?
    The CONSTRAIN without seeing what you did, may have made your actor stuck there and may prevent the move if doing it incorrectly.
    Not sure if I'm giving you what you want but it may be a start:
    I would create 2 real global attributes = TouchX and TouchY
    Rule:
    -When touch is pressed (on a grid actor):
    -Change attribute TouchX to mouse.position.x
    -Change attribute TouchY to mouse.position.y
    -Move to TouchX, self.position.y
    --Another rule inside this rule:
    --When attribute self.position.x = TouchX
    --Move to self.position.x, TouchY (EDIT: or this could be TouchX,TouchY)

    So this will move to the X mark horizontally then the Y mark vertically

  • tuftyfellatuftyfella Member, BASIC Posts: 17

    this works great, thanks, but i have to press inside the actor itself (on a corner for example) for it to move, i cant press on a grid actor and the hero actor moves to it

    1 2 3
    4 5 6
    7 8 9

    (imagine each number is a grid actor, just a plain old 100x100 actor which works like a button, when pressed has a fade effect to show this location has been pressed on)

    say my hero actor is positioned on top of grid actor 1 in the scene and i press on 9, i want it to move through 2>3>6>9 or 4>7>8>9 (lets not worry about obstacles for now :smiley:) , or rather constrain its movement through the center of these grid actors.

    how can i constrain it like this?

  • NNterprisesNNterprises Member, PRO Posts: 387

    So is your actor INSIDE 1, or on top of/above 1?

    And if you do what I said above it should work exactly like you said.

    If you tap 9, it will move to 3 (which is touchX), then move to 9 (which is TouchY).

    Since you are only MOVING TO TouchX, self.position.Y, only the X is different than the self.position, so it will be "constrained to that Y" and not be moving up or down. Then it moves DOWN.

    PM me if you are lost later

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    @tuftyfella said:
    1 2 3
    4 5 6
    7 8 9

    (imagine each number is a grid actor, just a plain old 100x100 actor which works like a button, when pressed has a fade effect to show this location has been pressed on)

    I've made you a quick demo (GS file attached):

  • tuftyfellatuftyfella Member, BASIC Posts: 17

    that is awesome Socks, exactly what i was looking to create :mrgreen:

    apologies NNterprises if i was most likely not explaining things properly. :smiley:

  • SocksSocks London, UK.Member Posts: 12,822

    @tuftyfella said:
    that is awesome Socks, exactly what i was looking to create :mrgreen:

    It probably needs cleaning up a bit, just thrown together, I'm sure there's probably a few edge cases where it goes weird, but should give you the basic idea.

  • mhedgesmhedges Raised on VCS Member Posts: 634
    edited August 2016

    @Socks,

    I saw this on my phone. I wondered if you used some pathfinding. I got home and saw the logic. So simple it's brilliant. Once again you took us to school.

  • tuftyfellatuftyfella Member, BASIC Posts: 17

    It really is very is very tidy and simple, there are a few bugs though, if u click ahead of the circle a few squares fast enough on a larger scale grid sometimes it jumps ahead a square to where your clicking instead of moving smoothly, also it can go off grid and then offscreen sometimes, not quite sure how to replicate that yet. I wasn't looking for something for fast paced button mashing anyhow so this suites my needs perfectly. :)

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2016

    //

  • SocksSocks London, UK.Member Posts: 12,822

    @mhedges said:
    I saw this on my phone. I wondered if you used some pathfinding. I got home and saw the logic. So simple it's brilliant. Once again you took us to school.

    I wouldn't go as far as 'brilliant' ! :D :p It's basically - touch the screen and record the X and Y touch positions - then move horizontally to the X touch position - then once there move vertically to the Y touch position !

    It's the same 'pathfinding' I use to get myself to the toilet.

  • mhedgesmhedges Raised on VCS Member Posts: 634

    @Socks said:

    It's the same 'pathfinding' I use to get myself to the toilet.

    Ever step on a Lego with the lights out? :D

Sign In or Register to comment.