- Home /
help with direction
Hello everyone. I have an array which is made up of the four directions : up, down, left or right. I have a grid of gameobjects in my game, I would like that when the mouse clicks any one of the gameobject and then a drag occurs in one of the directions, the object moves up, down, left or right, but only if the direction matches. Eg:
if (right == true){ if swipe direction = right <--- correct (show success) }
if ( right == true) { and swipe = (up, down, or left) <--- wrong (show failed) }
In essence, I am trying to set a script which states that when the object is touched and dragged, it will only move if the direction matches the random selection of a gameobject in the array. Can anyone help with getting this scripted from the pseudocode I have provided?
Thanks in advance.
To clarify, it sounds like when you say "the correct direction" you want your object to move forward if the direction of the drag is the direction the object was facing, no? Or is it that each object has a predefined direction that the user is trying to guess?
Each object has a predefined direction. When the swipe/drag occurs, if it is in the wrong direction no movement happens, however if it is in the predefined direction then the game object moves.
Answer by alexander11 · Dec 18, 2014 at 04:23 PM
try on the 2nd if statement if(!right == true) ! means not or false and stuff