• Advertisement
Sign in to follow this  

Unity FPS "Accuracy" value that affects the size of your crosshair

This topic is 2329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

So, I'm using Unity to make a small demo for an FPS. Some time ago, I wrote the accuracy values for my weapons and I figured I'd make the accuracy work like this: (100 - Accuracy) = pixels in size that your crosshair is. So 98 accuracy is a 2-pixel crosshair (I know that's tiny, but still).

But now I'm wondering if maybe I should be doing it a different way. I'm trying to make the firing so that it raycasts in a random position within your crosshair and then it creates a bullet in front of your gun, and that bullet's position is smoothed into the point where the raycast hit over like, .10 seconds or so.

However, I'm not sure if the accuracy will remain covering the same amount of game-space regardless of your resolution. Should I be doing a percentage of your screen 'area' instead of raw pixels as the size of the crosshair? Should I just use game units instead of pixels? What's the most common way for this to be done, and is that the best way?

Any help would be appreciated,

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I think the best way would be to keep resolution-agnostic; use game units. Offset the path of each bullet by a random angle, using you're accuracy metric (weapon precision, player's current speed, etc.) to control the size of the offset. You'd then work backwards into screen space to get the final size of the crosshair, which I suppose should be the angular diameter of the area in which the bullet might hit.

Share this post


Link to post
Share on other sites
Rather than approaching accuracy this way, why not approach it from the user's perspective? To the user, the "accuracy" of the weapon equates to how far away from an enemy they can be for all rounds aimed at the target to hit a part of the target. Weapons have a cone of fire within this accuracy range. So, if I aim perfectly at the center of the torso of a guard standing 100m away, a weapon which will ensure that every round I fire will hit the guy's torso is accurate to 100m.

If your game has a headshot mechanic, then you could instead use the head of the average target as the accuracy figure, so, a weapon accurate to 100m means that up to 100m away, any shot aimed perfectly(i.e. without user error) at the centre of a target's head will hit its head.

You could use "Minute of arc" as your input accuracy value, which is what rifle manufacturers use to measure their accuracy, [url="http://en.wikipedia.org/wiki/Minute_of_arc#Firearms"]http://en.wikipedia....of_arc#Firearms[/url]

This is far better than a value which has mathematical meaning to the programmer but is totally meaningless to the player, and which will force you to use trial and error while balancing the accuracy of your game's weapons. What you then do is add to this value (high values are worse) if the player is moving, subtract from it if they are crouched, etc.

[edit]
sorry, i misunderstood the intent of the OP. However, my answer to this is simple - make the gap in the crosshairs range between 0 MoA (crosshair is totally closed) and an arbitrary value somewhere in the high MoA's (say, 10 MoA) and use your current calculated MoA to interpolate between these two positions.

Share this post


Link to post
Share on other sites
So, I took your advice, johnchapman, and went with game units:

[code]var ray:Ray = movement.CharacterCamera.ViewportPointToRay(Vector3(0.5,0.5,.70));
var hit:RaycastHit;
weaponry.Text.transform.position = Vector3(0.5,0.5,1);
if (Physics.Raycast(ray,hit))
{
var offset:Vector3 = Vector3(0,Random.Range(-2.2,2.2),Random.Range(-2.2,2.2));
pos = (hit.point + offset);
weaponry.currentProjectile = Instantiate(weaponry.Bullet,transform.position,transform.rotation);
}[/code]

That pretty much just raycasts to the center of the screen then offsets that by a random number from -2.2 units to 2.2 units (those are game measurement units) on both its Y and Z (left/right and up/down). It then creates a bullet, which has its own code that moves itself to 'pos' over .10 seconds. It works very well and offsets them evenly regardless of how far you are from your target (I tested on a wall). Of course, I'm going to change it from 2.2 to something based on your accuracy value in the near future.

However, now I'm wondering how to find the proper calculation for sizing the crosshair appropriately based on your accuracy. I could try to figure out the percentage of your screen in pixels that the maximum offset is by using one of the WorldToScreenPoint functions (translates world space into screen space) and then sizing the width/height at double that value...? Think it'd work or have any suggestions?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Now

  • Advertisement
  • Similar Content

    • By Atwo Studios
       
      Hey guys,

      Anthony here from Atwo Studios bringing you some new updates for the new year!
      In this video I go over our game ROY, the new games and some general updates to the company!

      If you have not checked out ROY feel free to give it a try! Many people have said they enjoyed the game thus far!
      ROY: https://goo.gl/o6JJ5P
       
    • By Affgoo
      https://play.google.com/store/apps/details?id=com.NE.Alien
      still a lot of work to do, but its pretty stable  please let me know what you think <3
      Atlas Sentry is a game of destroy everything. Using your turret, simply swivel and shoot your way to victory, upgrading your weapons to unleash destruction on the variety of spaceships. The bigger your combo’s the more score you get! Earn silver as you play and then purchase new weapons and abilities to better deal with your enemy. Different enemies use different tactics and weapons, work out your own priorities in their destruction order. 

      Features: 
      **2 different game modes 
      **A level select mode with 20 difficult levels including a final boss, can you defeat it? **Arcade mode of endless destruction, how long will you last? 
      **High scores to compete against others, see who can take the top spot. 
       
    • By Chamferbox
      Chamferbox, a mini game asset store has just opened with some nice game assets, 
      Here you can find a free greek statue asset 

      Also check their dragon, zombie dragon and scorpion monster out:



      They're running the Grand Opening Sale, it's 30% off for all items, but for gamedev member, you can use this coupon code:
      GRANDOPEN
      to get 50% off prices What are you waiting for, go to
      http://chamferbox.com
      and get those models now!

      View full story
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064

      View full story
    • By DevdogUnity

      Ho ho ho
      Tis the season of Christmas surprises, and we have a awesome one for you! 🎅  
      Sponsored by all your favorite Unity Asset Store developers, Nordic Game Jam, Pocket Gamer Connects, and co-hosted by Game Analytics, we (Joris and I – Devdog) are launching the second edition of our yearly Christmas Giveaway Calendar for all Unity game developers!
      You can already now sign up right here.
       
      So what’s this all about?
      For the past weeks, we’ve been collecting sponsored gifts related to Unity (asset vouchers, product keys, conference tickets etc.), and throughout each day of December leading up to Christmas Day on the 25th, we will be sending out these sponsored gifts as early gamedev Christmas presents via e-mail to hundreds of lucky winners.
      The total prize pool is at $35,000, with over 1200 presents donated by the awesome sponsors!
       
      Merry Christmas from Devdog, Game Analytics, and every single one of the sponsors.

      View full story
  • Advertisement