- Home /
Android Drag By Steps
Hey people,
I'm currently working on a grid based game and my blocks uses integer values to represent in the grid like vector2(0,1),vector2(2,3),vector2(8,5) etc.I'm incrimenting the position by a step value of one like the following
//Function call will move the block to right one column
void MoveBlock_Right()
{
//Modify position to Right
transform.position += new Vector3 (1, 0, 0);
}
Here I'm calling the MoveBlock_Right() function using the "Input.GetKeyUp (KeyCode.D)" which acts as a trigger to step the block by one grid point for PC platform.Now I need to convert this to android platform.But i'm a little stuck here with this I need to move the block by the step value using touch-drag and more acceleration I put to my swipe should move the block more steps.
Can any one point some light to this..?
I think you want to realize two different things.
You have 2 ways to do this :
Crossy Road style, by taping on a position on the screen, the character moves to one case in the direction of your finger. It's the easier solution cause all your need to code is just a piece of code which catch a touch (Input.touches), compare the position of the touch with the middle of the screen and decide which direction your character needs to move by calling the kind of code you just post.
Clash of clans style (to put buildings), you touch your character in the middle and drag him accross the world. And this is a complete different code, you need to touch, verify if it touch your character (with a raycast for exemple), then follow the touch position to move your character with it, etc etc...
$$anonymous$$ake your choice :)
@Benou$$anonymous$$at Yes I know this but how to convert the acceleration of the drag to the step increment..?Any suggestion with a sample piece of code to get start with ?