Hi,
I want to control my player (single object) in same "swipe in ∞ " manner as in the game Crowd city by Voodoo. I have only got this far and the motion doesn’t seem on point, also the player stops at point when the device is continuously touched, I want it to keep moving till it goes out of screen.
public class PlayerControl : MonoBehaviour
{
private Vector2 finalPos;
private Vector3 finalTouch;
public new Rigidbody rigidbody;
private bool isMoving = false;
void update()
{
foreach (Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
finalPos = Input.mousePosition;
isMoving = true;
}
if (touch.phase == TouchPhase.Moved)
{
finalPos = Input.mousePosition;
isMoving = true;
}
if (touch.phase == TouchPhase.Ended)
{
finalPos = Input.mousePosition;
isMoving = true;
}
if (touch.phase == TouchPhase.Stationary)
{
isMoving = false;
}
}
if (isMoving)
{
Ray finalRay = Camera.main.ScreenPointToRay(finalPos);
RaycastHit hit_touch;
if (Physics.Raycast(finalRay, out hit_touch, Mathf.Infinity))
{
finalTouch = new Vector3(hit_touch.point.x, 0.75f, hit_touch.point.z);
}
Ray mouseRay = new Ray(finalTouch, finalTouch - gameObject.transform.position);
if (mouseRay.direction.x != 0 && mouseRay.direction.y != 0)
{
rigidbody.velocity = new Vector3(mouseRay.direction.x * 5, 0, mouseRay.direction.z * 5);
}
}
}
}