okay so, i’ve got the Drag Rigidbody script from the standard assets, now how can I make it so when you scroll it translates forward and backward
By “scroll” do you mean the scroll wheel? Regardless, the trick is to change the ‘distance’ used in the DragObject() function. For example, I’ve added this line to change the position based on the scroll wheel:
distance += Input.GetAxis("Mouse ScrollWheel"); // <<<<<<<<<<
Whole function:
function DragObject (distance : float)
{
var oldDrag = springJoint.connectedBody.drag;
var oldAngularDrag = springJoint.connectedBody.angularDrag;
springJoint.connectedBody.drag = drag;
springJoint.connectedBody.angularDrag = angularDrag;
var mainCamera = FindCamera();
while (Input.GetMouseButton (0))
{
distance += Input.GetAxis("Mouse ScrollWheel"); // <<<<<<<<<<
var ray = mainCamera.ScreenPointToRay (Input.mousePosition);
springJoint.transform.position = ray.GetPoint(distance);
yield;
}
if (springJoint.connectedBody)
{
springJoint.connectedBody.drag = oldDrag;
springJoint.connectedBody.angularDrag = oldAngularDrag;
springJoint.connectedBody = null;
}
}
You probably want to put some limits on the modification of distance…clamp it to the near and far clip planes at least.