Search Unity

Creating a Baldur's Gate Dark Alliance Style Camera

Discussion in 'Scripting' started by AnimusRex, May 12, 2019.

  1. AnimusRex

    AnimusRex

    Joined:
    Apr 26, 2019
    Posts:
    67
    Hi all, as the topic title says; I'm basically trying to create the same camera system as Baldur's Gate Dark Alliance.

    Some gameplay here if you're unfamiliar, skip to like 10 min mark;


    I've got it mostly working save for some polish.

    A couple issues arise; I'm trying to figure out how to have the "zooming in" effect not occur on a linear slide towards the character, but rather larger increments of view distance. IE instead of going 99 feet 98 feet 97 feet, I want 100, 75, 50, 25. I was trying to check if the right joystick axis is near maximum, but it doesn't seem to be working and I'm not familiar enough to know why.

    Past that, there's also the minor issue that this does zoom in on my characters feet a little too much. I've tried to correct it, and it removes the camera going in a straight line to the character, and sort of.. swoops? in instead. Hard to describe.

    Here is the code;
    Code (CSharp):
    1. public class CameraController : MonoBehaviour
    2. {
    3.     public Transform lookAt;
    4.     public Transform camTransform;
    5.  
    6.     private Camera cam;
    7.  
    8.     private float distance = 6.0f;
    9.     private float height = 3.0f;
    10.  
    11.     private const float distance_max = 12.0f;
    12.     private const float distance_min = 3.0f;
    13.  
    14.     private const float height_max = 6.0f;
    15.     private const float height_min = 1.5f;
    16.  
    17.     public float currentX = 0.0f;
    18.  
    19.     private void Start()
    20.     {
    21.         camTransform = transform;
    22.         cam = Camera.main;
    23.     }
    24.  
    25.     public void Update()
    26.     {
    27.         currentX += Input.GetAxis("Horizontal Rotation");
    28.  
    29.         if (Input.GetAxis("Zoom") >= 0.95 || Input.GetAxis("Zoom") <= -0.95)
    30.         {
    31.             distance += Input.GetAxis("Zoom") * 200;
    32.             height += Input.GetAxis("Zoom") * 100;
    33.         }
    34.  
    35.         height = Mathf.Clamp(height, height_min, height_max);
    36.         distance = Mathf.Clamp(distance, distance_min, distance_max);
    37.     }
    38.  
    39.     private void LateUpdate()
    40.     {
    41.         Vector3 dir = new Vector3(0, height, -distance);
    42.         Quaternion rotation = Quaternion.Euler(0, currentX, 0);
    43.  
    44.         camTransform.position = lookAt.position + rotation * dir;
    45.  
    46.         camTransform.LookAt(lookAt.position);
    47.     }
    48. }
    Thanks for any help!
     
  2. NicBischoff

    NicBischoff

    Joined:
    Mar 19, 2014
    Posts:
    204
    Save yourself some time and get dotween.
     
  3. AnimusRex

    AnimusRex

    Joined:
    Apr 26, 2019
    Posts:
    67
    Hey, I can barely use Unity at this point, not sure that adding tools will make my life easier :p

    What's it do? I took a brief look at their website and suffice to say, I don't get it.