Check if player object is right above this object

Hey Unitarians,

What I have is a player, and what I want is that when the player moves over a specific tile, the tile detects that the player is right above it, and freezes the player in the position until the user sets him free.

I’ve got the freezing all set up, but what I can’t figure out yet is how exactly I can have the tile detect the player right above it. The player moves in the x and y axises. The z-axis remains constant for all objects in the scene. This is the code I have so far:

if(transform.position.x == player.transform.position.x && 
		   transform.position.y == player.transform.position.y - 1)
		{
			Debug.Log ("Player is above me");
			// player is directly above this tile
			pausePlayer = true;
		}

I’m thinking of using raycasts, but I have absolutely NO idea how to use those things at all. If you are using raycasts, it’d be great if you could write some code so I can understand. If you are writing code, it’d be preferred if it was in C# but I’m sure once I get the concept I can translate from UnityScript if needed.

Also note:
Having a trigger collision will NOT work. I’ve tried, but it simply does not work with the gameplay.

Thanks in advance!
YomanAwe

make sure that the X position actually equals the EXACT same X position of player object, here is a ray cast code:

var hit : RaycastHit;
    
    if (Physics.Raycast(transform.position,Vector3.down,hit))
            {
                if (hit.gameObject == player.gameObject) //the players .gameObject is there because i'm not sure if you have it set to a transform, if it's a GameObject then you can be rid of it :)
                {
                    Debug.Log ("Player is above me");
                    // player is directly above this tile
                    pausePlayer = true;
                }
            }

that should work, hope I helped :smiley: be sure to tell me how it goes!