This question was
closed May 24, 2017 at 02:35 AM by
OnionRen.
Question by
OnionRen · May 22, 2017 at 02:14 PM ·
movementmultiplayerobjectfollowtouchscreen
How to make two characters to go to the direction of an touched item on a single screen
Hi everyone, I'm doing a 2D platformer with two players on a single screen with input touch to mobile.
The two players are on the same screen, each one has its own side, and they move to where I tapped on the screen, they can't pass to others sides like this.
The problems is: when I touch to grandma go to the stove and, AT THE SAME TIME, touch the kid to go to the sink, the grandma stop walking. How do I put multiple touch so I can move the grandma and the kid at the same time ?
And I wanted to know how to do when the players touch on the home appliances, the grandma and the kid go to that touched item (of their respectives sides) instead of walking freely like I did.
this is my movement:
public void MoveCharacter ()
{
if(Input.mousePosition.x < Screen.width/2)
{
Vector3 target = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, 10.0f));
player.transform.Translate (Vector3.MoveTowards (player.transform.position, target, speed * Time.deltaTime) - player.transform.position);
} else if (Input.mousePosition.x > Screen.width/2)
{
Vector3 target = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,Input.mousePosition.y, 10.0f));
player2.transform.Translate (Vector3.MoveTowards (player2.transform.position, target, speed * Time.deltaTime) - player2.transform.position);
}
}
void Update ()
{
MoveCharacter ();
}
Comment