Greetings, fellow developers! I hope you’re all doing well. In my previous update, I discussed my exploration of different approaches, such as dithering effects, to enhance player readability within the game. However, I have exciting news to share with you today. I stumbled upon an alternative solution that proved to be much simpler to implement and achieved excellent results.

Okay cool, let’s go!

Absolutely! Rather than modifying the visual properties of objects or walls, I decided to take a different approach. I implemented camera movement restrictions within the confines of each room, allowing it to move only a specific distance into the walls. By setting these boundaries, I effectively prevent the camera from reaching a point where walls obstruct the player’s view. This approach ensures that I maintain the integrity of the environment while guaranteeing an unobstructed view for the player.

Makes sense and how did you implement it?

Indeed, the implementation was surprisingly straightforward! To achieve this effect, I employed a raycast technique from the player to the camera. By casting a ray and detecting if it intersects with any obstacles, I am able to determine if there is an obstruction between the player and the camera. If such an obstacle is detected, I dynamically adjust the camera’s position accordingly. As the player moves away from the wall, I continuously monitor the distance between the camera and the player. Once it surpasses a predetermined threshold, I smoothly transition the camera back to its normal position, seamlessly following the player’s movement. This approach ensures that the camera intelligently adapts to the environment while maintaining an optimal view of the gameplay.

How about some code?

Sure! This is the raycast:

CheckObstruction()
{
    RaycastHit hit;
    if (Physics.Raycast(_target, -_aDistance.normalized, out hit, _aDistance.magnitude))
    {
        if (hit.collider.gameObject.tag == "wall")
        {
            Vector3 newPos = _camera.transform.position;
            newPos.x = hit.point.x - (hit.normal.x * 1);
            newPos.z = hit.point.z - (hit.normal.z * 1);
            _aDistance = _target - newPos;
        }
    }
}

_aDistance is the distance between player and camera.

This is the distance check:

NormalizeDistance()
{
    if (Vector3.Distance(_target, _camera.transform.position) > _nDistance.magnitude)
    {
        _aDistance = _nDistance;
    }
}

Bottom Line

While I acknowledge the potential benefits of using dithering and exploring other techniques in the future, I am currently convinced that the camera adjustment method I have implemented is the superior approach. This method not only addresses the visibility issue effectively but also serves as a solution for refining the camera system itself. By combining these improvements into a single solution, I am able to save time and effort, effectively “killing two birds with one stone.” Thank you for your valuable time and support. Stay tuned for more exciting updates!

Previous post #14 game dev stuff | dithering
Next post #16 game dev stuff | updating tile sets