Move character with touch on a grid

phatsamuryphatsamury Member Posts: 4
edited February 2012 in Working with GS (Mac)
Hi GameSalad community! I've been working on a puzzle game and thanks to Tshirtbooth's grid template I've made really good progress, but I've come to a halt. The grid template is set up so that the player moves from square to square with the use of the keyboard arrows keys, but I've tried everything, to the extent of my knowledge, to make the character move via touch on the screen.

I'd like the character to move to a square that I touch and keep the movement constrained to only X,Y meaning he can't move diagonally. So if I touch, say 5 squares to the right of the character, he/she will move (walk) 5 squares to the right.

Appreciate any help I can get and a special shout out to Tshirtbooth for all his great videos/tutorials!

Comments

  • MotherHooseMotherHoose Member Posts: 2,456
    when touch is outside … you can set a gameAttribute for touchX and touchY
    if you have an actual grid then use the gridCell coordinates to set those

    then do a Move To game.touchX … then game.touchY … or viceVersa
    (but don't use Move To behavior if your Actor can go off the screen!)

    @};- MH
  • phatsamuryphatsamury Member Posts: 4
    Thanks, MotherHoose! I'll give that a try and let you know how it goes.
  • phatsamuryphatsamury Member Posts: 4
    MH, I tried your suggestion, but I either didn't set it up correctly or misunderstood your instructions. Appreciate the help though. From reviewing other threads, it appears there's no easy way to make this work so I'm currently looking into other options.
  • MotherHooseMotherHoose Member Posts: 2,456
    no grid no attributes:

    image

    sorry about the blurriness of that image …

    basically it has touch outside … Move To: behavior
    and when collide with wall … same Move To: behavior

    but it works somewhat … know that it needs some tweaking

    @};- MH
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Looking at the template, the following might work:

    When mouse is down
    --Change Attribute: self.Position.X To: min((480-( game.grid size /2)), game.grid size *floor( game.Mouse.Position.X / game.grid size )+ game.grid size /2)
    -- Change Attribute: self.Position.Y To: min((320-( game.grid size /2)), game.grid size *floor( game.Mouse.Position.Y / game.grid size )+ game.grid size /2)

    Hope this helps!
    RThurman
  • phatsamuryphatsamury Member Posts: 4
    Thanks guys. Appreciate the help!

    RThurman, I set up the rule as recommended, but what is the *floor referring to?

    MH, I'm going to try your set up next and let you know how it goes.
  • MotherHooseMotherHoose Member Posts: 2,456
    floor() and ceil() are functions
    floor = round-down to a whole number
    ceil = round-up to a whole number

    same as in a room … the floor is down … the ceiling is up
    try them in a Display Text behavior …

    now you are going to have to learn some things about the other Functions! :-))
    not as hard as one thinks … just visit the Cookbook … reference Wikipedia
    and play around with them!

    @};- MH
  • phatsamuryphatsamury Member Posts: 4
    MH, you rock, man! I tried your solution and it works minus a few small nuances, like you said. I'm going to use that for now and test it with the other functions of my project.

    RThurman, thanks for your help too, but I think trying to keep the player constrained to the grid is a little too much for me now.

    Keep up the great work, guys!
Sign In or Register to comment.