Search Unity

Using cinemachine for a lock on system.

Discussion in 'Cinemachine' started by YuriyPopov, Jan 15, 2019.

  1. YuriyPopov

    YuriyPopov

    Joined:
    Sep 5, 2017
    Posts:
    237
    So far what I have come up with is to dynamically populate the target list in a Cinamachine Target Group component with the closest enemy and then using it in a virtual camera with it's Aim set to Group Composer and it's Body to a Framing Transposer that follows the main character. Now it's not looking or acting the best, but all I want to ask is if I'm on the right track here and I just need to tweak the numbers
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    I think we'll need a little more info here, like a detailed description of what you're trying to accomplish. Screenshots and movies of results would also help.
     
  3. YuriyPopov

    YuriyPopov

    Joined:
    Sep 5, 2017
    Posts:
    237
    Hey,
    Sure here it goes. So this is my basic set up.
    This is the state driven camera I'm using


    Here is the target group component


    And the Virtual Camera


    The code that sets the enemy in the target group is as follows :
    Code (CSharp):
    1.                 targetEnemy.target = indicatorObject.transform;
    2.                 targetEnemy.weight = 2;
    3.                 targetEnemy.radius = 1;
    4.                 //targetGroup.m_Targets.Append(targetEnemy);
    5.                 targetGroup.m_Targets[1] = targetEnemy;
    Here is a video of how it works :


    What I want to achieve is a lock on system more akin to Bloodborne or Devil May Cry. I want a way to tell Cinemachine to keep the enemy indicator in the center of the screen and keep the main character in the shot as well. Tell me if you need more info


     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    ok, if you want the reticle in the center of the screen to always be on your target then TargetGroup is definitely not the way to go. It will target the weighted center of the group, always. As soon as your player character is added to the group it will be ignored if it has zero weight, or shift the focus point if it has non-zero weight.

    Have a look at this thread, it might give you some ideas: https://forum.unity.com/threads/bes...s-style-target-lock-using-cinemachine.606418/
     
    CSNomadProductions likes this.