Jump to content
  • Advertisement
Sign in to follow this  
Lithic

Unity Targetting Cues

This topic is 2007 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

So my game's a third person space shooter. This causes a wierd problem with targeting as the player ship may not be pointing at the center of the screen at all times, which means crosshairs function kind of strangely and basically make it difficult to determine where exactly you're shooting (see attached screenshot for an earlier incarnation of this game that used a crosshair).

So instead I came up with a new system where there is no crosshair (see second screenshot), but each enemy ship has a targeting pattern that changes colors from red to green if they're in your sights. This targeting is fairly sophisticated in that it's not necessarily green if you're pointing directly at the enemy, but actually factors in the amount that you need to lead your shots to hit the enemy if they maintain their current velocity. However, when I set a few friends in front of this version and they seemed confused as to what the coloring meant. Once I explained it they seemed to get a little better at managing it.

While I could easily explain it away in some kind of tutorial part at the beginning of the game I wanted to get an opinion from the community about third person targetting and whether it's even desirable or if I should just do away with all targeting aids and err to the side of realism.

Since some weapons are fairly inaccurate or have tracking features, this complicates the situation even further.

Share this post


Link to post
Share on other sites
Advertisement
It seems like you've pretty much solved the math for this and you're more or less curious about the design. What I've used in the past is 2 cross hairs along with auto aim. The first cross hair represents where the player is aiming, the second represents where an enemy closest to that crosshair is, and when the player moves the cross hair close enough the first one jumps onto the second to show a lock on, and all rounds fired go towards where the player's cross hair is. This started out as a solution for the z point of where the player was aiming in our 3rd person shooter and eventually became an aim assist that the player could use. It took some of the challenge of shooting out of the game, but it meant that the challenge of the game was getting into cover, and then selectively taking out the targets by the danger priority each target presented. Quite impressive that you've solved the mathematics of this given you have player velocity and direction and enemy velocity and direction to account for. For accuracy we scaled the cross hairs to represent the accuracy of the selected weapon and for some weapons that accuracy decreased as they fired so thee player would end up firing short bursts to keep the shots focused in the reticule. We also used different textures for the cross hairs of different weapons. Another thing to keep in mind with a third person shooter is, that you need to solve that z-axis based on what target you think the player is aiming at for the shots from the player's avatar to hit the target instead of go around it. Which is important when the player needs to fire deflection shots (aiming ahead of the enemy) to score a hit. It's not an issue in first person shooters however. We had a bit in the game where the player fired a turret in first person against fast moving flying enemies, it didn't have a lock on, but it was a bit of a pain to get the deflection shots working intuitively since we needed to use the projected Z position of the target the player was aiming at to solve the z in the equation of what direction the bullet should go.

Share this post


Link to post
Share on other sites
About 10% of men are red-green colorblind to some degree, so those colors are pretty much the worst possible ones to indicate correct aim.
Change of color in general is slower and harder to see than a change in sight geometry. I'd suggest you make the sight change shape, add a box around it or something as the indicator.

Share this post


Link to post
Share on other sites
Stroppy - good call... Yellow/red or blue/red seem to be good choices from that standpoint.

Interesting post Kyall. Please post a screenshot if you have one, kind of curious how you handle the auto-adjustment of the Z-axis. When targeting enemies at different distances would the targeting "pop" around adjusting for different projection lengths?

The mathematics were a little fun. It's just a pretty simple system of vector equations to derive the formula you need, but solving it requires a few tricks. I already use the same formula so that the enemies can lead their shots too (otherwise they're hopelessly inaccurate).

Basically you start with:
finalPosition = initialPosition + velocity * time

What you want is to solve for any point at which a fired bullet will cross into the enemy's radius.

||(bulletInitial + bulletVelocity * time) - (enemyInitial + enemyVelocity * time)|| = enemyRadius

I'll let you figure out the rest of the proof for yourself, but basically you break each vector into it's component parts and solve for time with the quadratic formula. There should either be two real solutions or two complex solutions for time when you solve it. If there are two complex solutions it means the bullet will miss, if the solutions are real the bullet will hit.

The equation of course becomes trickier when you need to account for non-linear bullets like rockets (these have an accelleration component in my game).

Decided to post the code of the "IsTargeted" function so those who don't have the mathematics skills can use it, enjoy!


private static bool IsTargeted(Weaponry.Weapon weapon, PhysicsObject target, Player p)
{
var shootPosition = weapon.GetShootPosition();
var shootSpeed = weapon.GetShootVelocity().Length();

// Quadratic formula to calculate time for leading the shot
Vector3 shootVelocity = shootSpeed * p.Look;
var speedSquared = Square(shootSpeed);
var velocityDelta = shootVelocity - target.Velocity;
var positionDelta = shootPosition - target.Position;
var a = Square(velocityDelta.X) + Square(velocityDelta.Y) + Square(velocityDelta.Z);
var b = 2f * (shootPosition.X * shootVelocity.X - shootPosition.X * target.Velocity.X - target.Position.X * shootVelocity.X + target.Position.X * target.Velocity.X
+ shootPosition.Y * shootVelocity.Y - shootPosition.Y * target.Velocity.Y - target.Position.Y * shootVelocity.Y + target.Position.Y * target.Velocity.Y
+ shootPosition.Z * shootVelocity.Z - shootPosition.Z * target.Velocity.Z - target.Position.Z * shootVelocity.Z + target.Position.Z * target.Velocity.Z);
var c = Square(positionDelta.X) + Square(positionDelta.Y) + Square(positionDelta.Z) - Square(target.Radius) - Square(weapon.BulletRadius);

// Evaluate the quadratic formula, with a little modification
var inner = Square(b) - 4 * a * c;
var latterPart = (float)Math.Sqrt(inner);
return inner >= 0 && ((-b + latterPart) / a > 0 || (-b - latterPart) / a > 0);
}
Edited by jsuffolk

Share this post


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

  • Advertisement
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Aryndon
      Project Redemption is an semi-fantasy RPG with a linear story and an elaborate combat system.
      We are building in Unity and are currently looking animators and artists.
      What we are looking for
      -Someone who is okay with split revenue/profits when finished
      -Collaborate with others in the team. Do you have an idea/thought on what should be included? Tell us!
      -Someone who wants to work with people that are passionate about this project
      If you are interested. Please message me and I will get back to you as soon as possible! Or add me on Discord AJ#6664
    • By Aggrojag
      Hello!
      I'm working on a game that is a narrative driven dark comedy with some small aspects of platforming and puzzle solving. The project is rather small as well. It touches on topics such as suicide, mental illness, family, corruption, free-will, and redemption.
      This project is exercise in polish, this means some experimentation will be needed along with some reworking of assets as they're provided.
      This will be a revshare model.
      First, I'm looking for a 2D sprite artist, not pixelated, that can compliment the style of the attached images, and be similar to the temporary character.
      We are looking to bring on a SFX designer at this time. Full list of required SFX will be available upon request, as well as a build with all elements related to sound implemented in some form (many SFXs pulled from the web for now). Will likely require some field recording, and some pretty strange SFX for when things get weird. I imagine a good portion of these will be quite fun to create.
      Lastly, I'm looking for a male voice actor, English should be your primary language. There will be at minimum two characters that will need to be brought to life through vocals. The first voice is similar to Marvin from Hitchhiker's Guide to the Galaxy. A reference for the second voice would be a mix of Ren (Ren & Stimpy), and Android 21 (DragonBallFighterZ). Due to formatting, I'm not including YouTube links in the post, sorry.
       
      WIP Scene with our custom shaders attached (platforms are lazily placed, as this was an asset test):

      A scene with dynamic lighting and temp character:

       
      Unshaded asset:

      If you made it to the bottom, thank you, and I look forward to hearing from you.
    • By SickTwistGames
      Ok, firstly, Hi.
       
      This is my first post on this forum. I am an Indie Dev making my first game so bear with me when I say dumb stuff, I'm on a huge learning curve.
       
      My first question is about inventory systems for unity. I am trying to make a survival type game with crafting. I have purchased Inventory manager pro by devdog from the unity asset store and it seems like a pretty powerful assett but for an intermediate coder its a little tough to use.  I'm beginning to wonder if it was the right purchase.
      So my question is.... does anyone have any experience of inventory plugins / systems for unity and can anyone reccomend a system to me?
      It needs to have the following: Loot system, crafting system, character sheet, blueprint system,  character stats system. Ideally with as little coding as possible.
       
      Thanks
    • By ethancodes
      I've got a bug with my brick breaker style game. The bricks move down one line at a time ever 1.5 seconds. What appears to be happening is occasionally the ball will be just about to hit the brick when the brick moves down a line, and now the ball is behind it. I'm not sure how to fix this. I have two ideas but I'm not sure of implementation. 1 solution would be to check where they were and where they are going to be before rendering the frame. Then if they crossed paths, then register the brick as hit. Solution 2 would be change how the bricks move. I could maybe slide them down line by line, instead of a jump down. I'm not sure of this will fix the issue or not. Any ideas?
    • By Pixeye
      I wrote an extension for unity inspector that allows to group/fold variables. 
      Available on github  , cheers!

       
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!