Good morning. I want to make the control of the object, regardless of where you press (ie I’ll move to the right and the object moves to the right, etc.). Now I have realized when I click on a point, the object moves there.
I want the object to move according to the previous touch. Instead of coordinates.
Sorry for my english.
Now like:
Code
/// <summary>
/// </summary>
void MoveToAdd(float addX, float addY)
{
float x = Mathf.Lerp(cachedTransform.position.x, cachedTransform.position.x + addX, Time.deltaTime * SPEED_TOUCH);
float y = Mathf.Lerp(cachedTransform.position.y, cachedTransform.position.y + addY, Time.deltaTime * SPEED_TOUCH);
x = Mathf.Clamp(x, LEFT_BORDER, RIGHT_BORDER);
y = Mathf.Clamp(y, UP_BORDER, DOWN_BORDER);
cachedTransform.position = new Vector3(x, y, 0);
}
/// <summary>
/// </summary>
private void Control()
{
isControl = false;
if (controllerType == ControllerType.Swipe)
{
if (Input.touchCount > 0)
{
Touch t = Input.touches[0];
pos = Camera.main.ScreenToWorldPoint(t.position);
float x = (pos.x + previousPosition.x) >= 0 ? speed : -speed;
float y = (pos.y + previousPosition.y) >= 0 ? speed : -speed;
if (!isControl) MoveToAdd(x, y);
previousPosition = Camera.main.ScreenToWorldPoint(t.position);
}
}
else
{
Accelometer();
}
}
