How to have second cinemachine camera point at the exact spot when aiming?

I have a third person controller that I’ve modified to my heart’s content. Now I’m adding aim mode and it has me wondering what the right approach is. My aiming camera zooms in and out just fine, but because it’s offset a bit on the x and y, when I aim the reticle is also offset a bit. I’m trying to rack my brains on the right approach but, because of depth (z-axis), all roads seems to lead to raycasting. I want it so that when I aim at something, I’m aiming at the same exact pixel I was looking at before I started aiming, but I need to do that after switching to secondary camera used specifically for aiming that is slightly offset so that it emulates someone leaning their head to peer through the scope on their weapon.

What’s the right way to go here?

Many thanks in advance!

Anthony

This tutorial is really good:

Hi! Thanks for replying. I’ve watched that one, but they don’t address the issue, they have an offset issue as well which they don’t address, they just dance around it by giving you a second reticle to address a related problem, and they’re raycasting. I’m guessing I need to raycast from main camera to find the hit point in world space, and orient the aim camera towards that, but I’m wondering if there’s a better and more standard way of doing it.

It sounds like you understand the issue, and it’s pretty much the same as in real-life: when you aim a rifle, even a laser rifle, you are never going to be looking precisely down the bore, which is the actual axis of fire.

You have two lines, assuming no bullet drop:

  • your eye line
  • the bullet line

This means you either have:

  • two parallel lines, introducing the offset you mention
  • two converging lines that touch at the point of impact

BUT!!! for converging lines, the point of impact moves with the target distance… and anything in between you and the target could obscure one line and not the other.

Or you could fix the convergence point, which is how a rifle is trued out at a particular range.

There actually isn’t really a standard one-size-fits-all solution, just like real life. Aiming is as much an art as a skill.

Games fall into largely two camps:

  • have the two lines actually offset by an amount (either the correct eye-to-gun amount or a smaller amount) and simply deal with you hitting obstacles with the bullet, or being able to fire around obstacles blocking your view
  • just pretend the bullet came out of your eye and hits precisely where your gaze is.

And some games actually behave differently:

  • at different ranges
  • with different weapons
  • based on if you are looking aim-down-sight or firing from the hip.
  • if you are moving or stationary or prone or crouching

Some games might even do both simultaneously and take the one that gives you a hit, just to “be nice” since that makes for good game experiences.

Also, you don’t need a camera to raycast. You can raycast just from a Transform placed at the tip of your weapon, or obviously anything that gives you an origin: and direction: to cast from.

So in summary, kinda up to you as the game designer. :slight_smile: