I'm using Third Person Controller with cinemachine integration, when i fire a projectile,it's not moving towards the crosshairs position.How do I fix this,thanks
I use free look for my camera,and i set Player's transform to Follow and and Look field.The look direction is not correct,it's always lower than the corsshair positionWhat Cinemachine camera type are you using? Does CinemachineViewType.LookDirection return the correct direction? It uses CinemachineBrain.CurrentCameraState to determine the camera rotation.
no,the debug ray is not aiming the crosshairs position.I notice CinemachineViewType use orientation to caculate the LookDirection,while ThirdPerson use ray cast.Could this be the cause of the incorrect LookDirectionIf you draw a debug ray within the LookDirection method does it look correct?
Thanks for the example,my results are the same.In the ShootableWeapon.cs script,when invoke ProjectileFire method,the projectile use the camera's direction(the green line),and start from the fire point,so it's always lower than the target.Is there a way to fix this?I just placed a cube in front of the crosshairs and my results are below. The green line is the debug ray from the CharacterIK component and the while line originating from the top of the character is from the CrosshairsMonitor:
View attachment 7592
View attachment 7593
You could try adjusting the Look Direction Distance on the ViewType - this is what determines how long the lines extend.
Thanks for the help,I'll give it a tryThere isn't a built in way, but until I add it as a new feature you could subclass the View Type and return a slight offset to the LookDirection method.
Hi, have you found a way to fix that? I have the same problem, can't move the crosshair, the green line does not follow the crosshairsThanks for the help,I'll give it a try
Use ray castHi, have you found a way to fix that? I have the same problem, can't move the crosshair, the green line does not follow the crosshairs
Thanks for answering. Where did you do that? Did you subclass the cinemachine viewtype? Did you do that in the shootableWeapon class?Use ray cast
var ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width * 0.5f, Screen.height * 0.5f, 0));
var hits = Physics.SphereCastAll(ray, 0.25f, 50, m_ImpactLayers, QueryTriggerInteraction.Ignore);
if (hits != null && hits.Length > 0)
{
var hitObject = false;
foreach (var hit in hits.OrderBy(i => i.distance))
{
if (hit.transform.IsChildOf(m_Character.transform)) continue;
var dir = hit.point - firePoint;
if (Vector3.Dot(dir, Camera.main.transform.forward) < 0) continue;
direction = dir;
hitObject = true;
break;
}
if(!hitObject)
direction = Camera.main.transform.forward * 50 + Camera.main.transform.position - firePoint;
}
else
{
direction = Camera.main.transform.forward * 50 + Camera.main.transform.position - firePoint;
}
I did that in the shootableWeapon,you can also subclass the cinemachineviewtype.Thanks for answering. Where did you do that? Did you subclass the cinemachine viewtype? Did you do that in the shootableWeapon class?