Move character with touch on a grid
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!
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
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
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
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
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.
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
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!