Hello! After using the 3RD person unity asset a little, I wanted to know if it was possible to make a target on camera follow type of. The camera would follow the player and look at an object. Is there a way to script this (have the transform of the closest object with a certain tag) or is it a built in component? Thank you!
I've gave it a thought, is it possible to get a transform out of a collision? Like if I were to have the camera hit a raycast, and if it hits a collider, then give back a transform. Is it do-able though?
Hello Yes, look at our DualTarget example scene. You can get our example scene from the Package Manager -> Cinemachine -> Samples -> Import. Yes. See the example: https://docs.unity3d.com/ScriptReference/Physics.Raycast.html. You can get the collider or transform from RaycastHit.
Hello again! I was wondering how can I store the transform of the object the ray cast hits? Is it after the Vector3 direction?
Sorry! My main goal is to have the cinemachine camera "Look at" with none. Whenever I press a key, I want a ray to be cast from the camera. It has to go through everything but a layer I'll call "Targetable". If it hits something with this layer, the script needs to send to the cinemachine camera the transform of the object targeted. My issue right now is how to collect those transforms data and store them in some kind of variable I can assign to the LookAt. Sorry if this doesn't make it more clear. I'll try to draw it.
You can get the target from Raycast, and then assign it to the vcam's LookAt. Try this script: Code (CSharp): using Cinemachine; using Cinemachine; using UnityEngine; public class VcamTarget : MonoBehaviour { public CinemachineVirtualCamera vcam; public float maxDistance; public LayerMask layerMask; void Update() { if (Input.GetKeyDown(KeyCode.Space)) { if (Physics.Raycast(vcam.transform.position, vcam.transform.forward, out var hit, // this has information about what was hit maxDistance, layerMask)) { vcam.LookAt = hit.transform; } } } } You can attach this script to any gameobject, then set the vcam, maxDistance, and layerMask in the editor inspector.