Search Unity

3rd person line of sight different than cameras line of sight

Discussion in 'Scripting' started by tree_arb, Mar 28, 2021.

  1. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    How is this problem usually solved in 3d space when there is no defined target with a third person camera following a player?

    The cameras line of sight looking at an object is different than the line of site from the player.

    If you aim at a specific target through the camera, I can send a projectile from the 3rd person player to that point and everything is good. (creating a triangle with 2 separate lines of sight)

    However if I am looking past the target at nothing, I have no concrete target point. So the trajectory of a missile fired from the player is dependent on the arbitrary distance I set from the cameras line of site.

    Looking at this illustration. The cameras line of site (red line) intersects a target, the player fires towards that target, all is good.

    If the camera is looking at the blue line direction. I must choose a distance on the blue line to fire towards. One solution I came up with is to collect objects and assume what the player might be pointing near, to create the point, but that's not fool proof.

    In the real world scenario what happens is I can shoot an object, but if I'm pointing at a close miss, the projectile seems to be wildly missed instead of skimming next to the target, because I may or may not have a similar distance set. Hope that makes sense.

    edit: sorry not exactly scripting, feel free to move the post


     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,742
    +1 for linking a picture to GTA... ah, Catalina, what a dynamic lady.

    For the actual issue, there's lots of solutions. Auto-aim is a thing, and so is offsetting your bullet trajectory to go down the camera view at the spot, or at least do so from the player forward.

    Or perhaps just fire from the player's hand at wherever the reticle hits a target in scene, which of course might make you miss (eg., if there was a low sports car (a Banshee!)) parked halfway up the driveway here. The bullet from the player might hit the car, the LOS from the camera would not.

    You kinda gotta play with it in your specific context, see what works best for you. Note also that GTA has an ADS mode where you pull left trigger and the camera comes down much closer to the true line of sight of the gun.
     
  3. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    thanks good solutions. I am partially implementing some of them.

    "auto aim"
    this is the next step for me, I will be working on this today, lock to target for some weapons.

    "offsetting your bullet trajectory to go down the camera view at the spot"
    for bullet type weapons I do this and its fine because you don't see the projectile in full. The problem comes in when I use rocket launchers where you watch the rocket go from player to a non defined target target.

    "Or perhaps just fire from the player's hand at wherever the reticle hits a target in scene, which of course might make you miss"
    this is what I do now and it works well. The camera Aim line of sight (reticle I guess its called) hits a target I can fire a rocket to that point in 3D space, it hits target great, if the enemy moves it doesn't, that actually perfect.

    The problem comes in where I do not have a defined target (well actually i sort of do). If the reticle is pointing just past the player, the camera target point may hit terrain far away. This would be fine if the two lines of sight matched, but the triangulation of the two separate line of sites puts the players rocket trajectory in a correct, but undesired path.

    example:
    -camera aim at target 10 units away. player fires a path at that point in 3d space hitting target.

    -camera just missing the target (shooting past the target)... the target is now 100 units away hitting terrain. camera firing a rocket would be fine, but player firing to that distant point due to the offset, the rocket will not wiz by the target, but instead appears to be a bad miss as the trajectory is different. If I were to put the target distance just next to target, it will wiz by correct... but is the user aiming near this target at 10 units away, or a different target at 50 units away, we do not know.


    "Note also that GTA has an ADS mode where you pull left trigger and the camera comes down much closer to the true line of sight of the gun"

    I've got some of that going on, many weapons with different uses. I think I need to play GTA again to see what they do I kind of forget.

    The screen shot i posted has the aim above the player, my actual game is more offset to the side causing the effect to be worse.

    Thanks I think you are right its just going to have to be a combination of them all.

    -Invisible bullets not a problem.

    -throwing spears and items, I think I will implement auto aim

    -rocket launcher... I really like how i have it free form now, everything works great except if you aim past the enemy at a distance trajectory looks bad in game. I cannot fake a distance to path through because there are enemy as all sorts of distances.















     
    Kurt-Dekker likes this.
  4. Djabenv

    Djabenv

    Joined:
    May 16, 2018
    Posts:
    19
    I'm trying to do something similar. I'm quite new to Unity so not sure if it's the right approach but it works for me.

    Could you set a target limit distance (forward from camera) and then raycast forward from camera. If you hit an object before the limit distance, set that as target, if not, set the limit distance as the target.
     

    Attached Files:

    tree_arb likes this.
  5. tree_arb

    tree_arb

    Joined:
    Dec 30, 2019
    Posts:
    323
    Yes this is exactly what i am doing now, and it works most of the time, but my scene has an open layout where you might shoot a rocket just past that target to a target in the back.

    Where the user expects the rocket to wiz right by fhe first target... It does not due to that line of site. So the choice of what the max distance is, is difficult.

    When i went back and played it again after this post i was like, ehh, its not too bad, and i have not adjusted it yet.

    I think you are correct that max distance is important as a default, and perhaps a "smart" system to adjust that max distance on the fly as well.

    If i hit a time where i am aiming just next to an enemy, and there isn't much the user may be pointing at in the background, perhaps i set toggle max distance to that enemy distance at that shot.

    I think any way you spin it what you end up with is an aiming system that feels slightly wrong 5% of the time.

    I still haven't gone back and revisited GTA perhaps they avoid the setup somehow. Like auto lock aim and stuff