I am trying to create a little system that will allow me get the position of my mouse on the sceen space around a object. and have it control the distance/rotation of the object. So far i have it some what working but i am using a plane to achieve the desired effect, The draw back of this is. If the camera isn’t far enough away to see the place “area!” then i can’t set my distance to maximum etc. Here is what i got so far in my dragging method. I want really to use the “camera view” as the plane effectively to control it all.
private void Dragging()
{
if (isLocalPlayer)
{
if (planeD.GetDistanceToPoint(transform.position) != 0)
{
planeD= new Plane(dragPlane, transform.position);
}
mRay = Camera.main.ScreenPointToRay(Input.mousePosition);
float intersect = 0.0f;
if (dragPlane.Raycast(mRay , out intersect ))
{
mousePos3D = mRay.GetPoint(intersect );
dDistance = Mathf.Clamp((mousePos3D - transform.position).magnitude, 0, basePower);
if (dDistance * powerMulti< 1) dDistance = 0;
powerV = mousePos3D - transform.position;
powerV .Normalize();
powerV *= dDistance * multiPower;
line.enabled = true;
// draw the line
line.SetPosition(0, transform.position);
line.SetPosition(1, transform.position + -forceVector / lineDrawMaxDistance);
}
pUI.powerBar(forceVector.magnitude);
}
}