Targeting System
I feel this may require a separate post, as I want the chance to explain my technical reasoning behind things. So, pardon me for the deviation, but this is what I want to specialise in at university so I'm going to take the chance. The easy part is actually the visuals.
The visuals side of things are easy. All I have here is two things - a UI widget (like the HUDs I've done before), with two circles rotating. Along with that, however, I also have a thing known as a 'billboard material' This is simple a sprite that scales with the screen, rather than scaling with distance. What's difficult, is putting this little element into action.
This is what does the magic - this takes the position of the player, along with the position of the enemy target, and does some math to figure out where the player should aim at to be able to hit the target.
First, it takes these two locations and subtracts them from one another, and turns those 3 values into a single one (the length). Basically, this is creating a right triangle - the resulting value I get is the slanted line of said triangle. I then divide that value by the speed of the bullet in cm/s, which is 5000. This gives me a value which I can multiply by the velocity of the target. This gives me where the target will be when the bullet has travelled far enough to get from A to B. I then add that on to the target's location, which gives me a value relative to the world/environment. This is where the targeting reticule must go, and also where the player must aim, to be able to hit the target correctly.
You can see the result of this math below!
The visuals side of things are easy. All I have here is two things - a UI widget (like the HUDs I've done before), with two circles rotating. Along with that, however, I also have a thing known as a 'billboard material' This is simple a sprite that scales with the screen, rather than scaling with distance. What's difficult, is putting this little element into action.
This is what does the magic - this takes the position of the player, along with the position of the enemy target, and does some math to figure out where the player should aim at to be able to hit the target.
First, it takes these two locations and subtracts them from one another, and turns those 3 values into a single one (the length). Basically, this is creating a right triangle - the resulting value I get is the slanted line of said triangle. I then divide that value by the speed of the bullet in cm/s, which is 5000. This gives me a value which I can multiply by the velocity of the target. This gives me where the target will be when the bullet has travelled far enough to get from A to B. I then add that on to the target's location, which gives me a value relative to the world/environment. This is where the targeting reticule must go, and also where the player must aim, to be able to hit the target correctly.
You can see the result of this math below!
This is all of the functional pieces for my UI - and I'm rather happy with it visually, too! However, it's not everything I planned, as I haven't achieved some of the features I wanted to. This is, however, acceptable for the usage of my game. Perhaps in the future, the I will improve on this design when I come to continuing development!



Comments
Post a Comment