open Door when aproached

Maybe someone could help with this:
I want to run towards a door and when you get in distance maybe 10 it starts opening. But it opens more as you get closer. If you backup it closes. It starts at dist. 10 Fully rotated 90 degree when dist. is 2

Its no problem for me to rotate something endlessly. Or to Get.Distance beetween Door and Player.
But how do I wire Distance to openning Degree ???

So you can:

  1. Rotate an object ok?
    and
  2. Get the distance between the player and the door?

How about setting the doors rotation = (Distance <= 10 ? (Distance > 2 ? 90 / Distance : 90) : 0);

so at distance = 10 it’s rotated 9 degrees at distance = 2 then its rotated 90%;
the last increment may jump a little with that calculation but I’m trying to keep it simple.

Someone helped me thanks :):
This script rotates an Object as you get close to it. And reverse… So a Door will open as you walk towards it.

var other : Transform;

function Update () {
	if (other)
	{
		var dist = Vector3.Distance(other.position, transform.position);
		//print ("Distance to other: " + dist);
	}
	
	if (dist <= 10)
	{
		print ("Hello");
		transform.localEulerAngles.y = (10-dist) * -20.0;
	}
	else
	{
		transform.localEulerAngles.y = 0.0;
		print ("Goodbye");
	}
}

Next to figure out would be two Doors slide open.

And more interesting: How do I trigger sound, squeeky opening? :wink:

I would like to have the same thing for a sliding Door.
This is as far as i got.

var other : Transform;

function Update () {
	if (other)
	{
		var dist = Vector3.Distance(other.position, transform.position);
	}
	
	
	
	if (dist <= 4)
	{
		transform.localPosition.z = 8;
	}
	else
	{
		transform.localPosition.z = 6;
	}
	
}

The Door jumps from one position to another. I set the Position to LocalPosition but it remains to be Worldspace ? :?