I’m creating a game with a 3th person view. The camera follows the player throughout the map. But if I get to the very bottom of the map, the boundary (box) stops the player. The camera is following from a small distance, resulting the camera to be found at the other side of the wall (not seeing the player).
I’m trying to solve this problem by casting a Raycast to the Player GameObject. If the player is not seen, the camera should move along the y-axis (up) untill he sees the player again.
In the current code I have, I try to raycast and get information about the hitted object. The camera always looks at the player object. Even though, sometimes I get the message “Block” and sometimes the message “Plane”, but never “Player”, “Sphere” (which is the player’s hull) or “Boundary”. What is required for the raycast to see/hit them?
Current code:
var hit: RaycastHit;
var ray: Ray = camera.ScreenPointToRay(target.transform.position);
if (Physics.Raycast(ray, hit)) {
var objectHit: Transform = hit.transform;
Debug.Log(objectHit);
}