Hi
@Justin . We took your point into consideration and edited the
CinemachineViewType.cs script. We added some lines of code in the LookDirection function. And its working perfectly. The projectile now moves to the crosshair's direction & position.
We took the
ThirdPerson.cs script as reference and added some lines from this script's
LookDirection function.
Here's the code that we changed:
(P.S: I have provided the script in next comment)
public abstract class CinemachineViewType : ViewType
{
...
/// <summary>
/// Returns the direction that the character is looking.
/// </summary>
/// <param name="lookPosition">The position that the character is looking from.</param>
/// <param name="characterLookDirection">Is the character look direction being retrieved?</param>
/// <param name="layerMask">The LayerMask value of the objects that the look direction can hit.</param>
/// <param name="includeRecoil">Should recoil be included in the look direction?</param>
/// <param name="includeMovementSpread">Should the movement spread be included in the look direction?</param>
/// <returns>The direction that the character is looking.</returns>
public override Vector3 LookDirection(Vector3 lookPosition, bool characterLookDirection, int layerMask, bool includeRecoil, bool includeMovementSpread)
{
//Custom Code
var collisionEnabled = m_CharacterLocomotion.CollisionLayerEnabled;
m_CharacterLocomotion.EnableColliderCollisionLayer(false);
//End
if (m_UseCharacterLookDirection) {
return (CharacterRotation * Vector3.forward);
}
var crosshairsDeltaRotation = characterLookDirection ? Quaternion.identity : GetCrosshairsDeltaRotation();
//return (m_Brain.CurrentCameraState.FinalOrientation * crosshairsDeltaRotation) * Vector3.forward;
//Custom Code
var rotation = m_Brain.CurrentCameraState.FinalOrientation * crosshairsDeltaRotation;
Vector3 hitPoint;
if (Physics.Raycast(m_Transform.position, rotation * Vector3.forward, out var hit, m_LookDirectionDistance, layerMask, QueryTriggerInteraction.Ignore)) {
hitPoint = hit.point;
} else {
var offset = Vector3.zero;
offset.Set(0, 0, m_LookDirectionDistance);
hitPoint = MathUtility.TransformPoint(m_Transform.position, rotation, offset);
}
m_CharacterLocomotion.EnableColliderCollisionLayer(collisionEnabled);
var direction = (hitPoint - lookPosition).normalized;
return direction;
//End
}
...
}
Here's the video after the code fix:
(Now the projectile spawns in the crosshair's direction, where we are aiming)
But now we are facing another issue. When we aim, the crosshair points down for some reason. This doesn't happen with the Adventure View Type. Only happens with Cinemachine View Type camera. Also, there's some weird glitch that occurs when we aim at the Dummy (Boxing Joe).
Here's a video for reference:
(In the above video, when we aim, the crosshair's position changes and goes down, and resets as we un-aim.
And when we aim at the dummy camera rotates around weirdly)
Some help on this would be appreciated.
Thank You.