Hello, What is the best way to move object between two points based on mouse movement*(these two objects can stand diagonally)*? Also
is there any easy method to detect if a player turns the mouse in a circle and how many times. Thank for any help.
here’s a simple class that would identify when you click your mouse button 0, and then compare the cursor distance from that original click.
the distance from the original click (in any direction) should control the movement of an object for 10 units straight up.
I haven’t tested this, but this is the concept you’re looking for. adapt to your needs.
hope that helps
using UnityEngine;
using System.Collections;
public class MoveTest
{
public Transform mover;
public Vector3 startPoint = Vector3.zero;
public Vector3 endPoint = new Vector3(0, 10, 0);
public float mouseDistance = 5f;
private Vector3 mouseStart;
void Update()
{
if(Input.MouseButtonDown(0)) // only run once per mouse click
{
mouseStart = Input.mousePosition;
}
if(Input.MouseButton()) // run continuously as long as mouse button is held down
{
float moveDistance = Vector3.Distance(mouseStart, Input.mousePosition)
mover.position = Vector3.lerp(startPoint, endPoint, moveDistance / mouseDistance);
}
}
}