it’s a math question. i couldn’t form it as text, so i made a picture
If the black line is pointing the same direction that the player is facing, you can make a script and attach it to the player’s GameObject, and in that script, you can use transform.forward
to get the direction the player is facing.
In the C# code, you’d write it as:
Ray ray = new Ray(transform.position,transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray,out hit,Mathf.Infinity)) {
//if an object with a collider was hit by the ray, Physics.Raycast() will return true
//the "hit" variable now contains information about what
//the raycast intersected with first - look at the
//documentation for Physics.Raycast for more info:
//http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html
}
This might be a hacky solution. But I would use raycasting with a ray thats bellow the player and parallel to the players rotation. Then change the position.y of the hit info to the max bound y of the cube. The ray in this case would start inside the cube the player’s standing on so I’m not sure if it will think it’s colliding with the current cube the players on. To solve this you could use raycastall and ignore the first hit. Hope this helps.