Skip to content

mnijaki/AutoAimBowAndArrow

Repository files navigation

Automatic aim on target in camera frustrum + 3D arrow trajectory algorithms

This project consist of:

  • Input handling:
    • Input handling is based on "Chop chop" Open Projects and new Unity Input System.
    • Main difference is that "InputReader" class is no longer a ScriptbleObject, but just a MonoBehaviour.
    • Link to video from Open Projects.
  • Automatic target chooser:
    • "TargetChooser" class is responsible for choosing object as a target.
    • First it detects all "ITargetable" objects in the scene that are in camera view frustrum.
    • Then it sets "ITargetable" object, that is closest to the shooter, as a target.
    • WARNING: currently "TargetChooser" does not detect if something is obstructing line of view to target.
      It was deliberate decision to not implement this, because main purpose of project was to test trajectories of projectiles,
      and it was easier to do that without worrying about obstruction of objects.
      If you need, just implement this functionality by simple raycasting or something more advanced.
  • Weapon system and projectiles trajectory methods:
    • There are two approach of computing trajectory of projectile:
      Height based and velocity based.
      In most cases you can choose one and then remove unnecessary code, thus simplifying code.
    • Weapon types (ScriptableObjects):
      • Height based
        • You set how projectile movement will look like based on height of the parable (arc height in inflection point).
      • Velocity based
        • You set how projectile movement will look like based on intial velocity of projectile when launched.
    • "WeaponHandler" class:
      • Responsible only for switching weapon type(height or velocity based) and invoking launching of projectile
    • Launching of projectiles is handled by one of two classes:
      • "HeightBasedProjectileLauncher"
        • This class will compute initial velocity and angle that should be used to launch projectile.
          Projectile will travel along arc of given height (obtained from "WeaponType").
          There is also an option to flatten the arc based on the distance between shooter and target.
          The closer the shooter is to the target, the more flattened the trajectory becomes.
        • WARNING: if the shooter and the target are not on the same level ground (their 'y' positions are different)
          the height of the arc will be modified to compensate for the difference.
          Depending on your needs you can change that part of the code.
      • "VelocityBasedProjectileLauncher"
        • This class will compute initial angle that should be used to launch projectile.
          Projectile will travel along arc computed based of initial velocity (obtained from "WeaponType").
        • Depending on the situation, the equation for computing angle of the launch requires different equation transformations.
          There are three main situations:
          • Shooter and target are on the same level (their 'y' positions are the same)
          • Shooter is below target
          • Shooter is above target
        • All trajectory code is commented pretty heavily so it would be easier to understand equation transformations.
          There are also links to videos that explains equations used in code.
  • Arrow handling:
    • "ArrowControler" class
      • Responsible only for destroying of the arrow
    • "ArrowLaunchData" class:
      • Data needed to launch arrow (eg. intial velocity, angle and etc) obtained from projectile launcher.
    • "ArrowMover" class:
      • Responsible for launching arrow (sets initial velocity on rigidbody)
      • Responsible also for pointing the tip of the arrow to match the trajectory
    • "ArrowPositionPredicter" class:
      • Responsible for drawing projectile trajectory
  • Custom character controller:
    • Physics based character controller + Cinemachine
  • Interactables:
    • "PickUpHandler" class:
      • Used to switch weapon types
    • "Elevator" class:
      • Responsible for handling elevators


Project preview:

Preview

Screenshots:

image

image

image

image

image

image

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published