0
\$\begingroup\$

I am continuing my previous question( link ). Now its working as per this demo.

and the coding written to set cutoff is here :

function Update () {

    renderer.material.SetFloat("_Cutoff", Mathf.InverseLerp(0, Screen.width, Input.mousePosition.x)); 

}

But i want to set cutoff value , depending up on distance between two object.

one object position will be static. and i am moving another object and if my object gets far distance then cutoff should be 0. and if the object gets closer then depending up on the distance between these two object , i want to set cutoff value.

so how do i set cutoff value?

Please help me guys?

Thanks in advance for your support and help in advance.

\$\endgroup\$
  • \$\begingroup\$ So you problem is to find the distance between two objects in real-time? \$\endgroup\$ – Korchkidu Dec 7 '13 at 7:03
1
\$\begingroup\$

Just compute the length of the distance vector between the moving object and the static object using this code:

// Distance: length of vector (static - moving).
float distance = Vector3.Distance (staticObject.transform.position, movingObject.transform.position);

Pass the float to your material and use it in your shader.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.