Circle crosshair that fits the bullet spread
Hello, I’m building a game where the guns have a circle crosshair that indicate the bullet spread. It is supposed to work with the players current weapon skill. Example: Player has 0 skill in assault rifles, his crosshair is gonna be very big and so is his bullet spread. When reaching higher levels in assault, his circle narrows down and so does the bullet spread. I am very beginner and starting to make an FPS game and I want to start with this part because it has a huge impact and is one big essence of the game! How can I achieve this? Pointers to reading material, tutorials, code samples are appreciated
Answer by streeetwalker · Sep 11, 2020 at 09:30 AM
This is really simple to do using a number of approaches.
One way that may be the simplest is to create the crosshair graphic and import it. Then create a material and use the crosshair graphic for the albedo texture. Then use the material on a plane.
Drag the plane with the crosshair texture material applied to the project folder, say in a prefab folder, to create a prefab out of it. Make sure the prefab origin is at 0,0,0 and it's scale xyz are all set to 1,1,1..
You can then instantiate this where ever you want (or author it driectly into your guns). and to set different spread sizes, set the transform.localScale = new Vector3( xS, yS, zS ) where xS, yS, zS are all the same number. For example, 1 is original size, 0.5 is half size, 2 is double size, and so on.
If you are authoring it directly into the gun, you can just resize it in the inspector or using the scale tool without any script.
Okay I think I understand, it is basically a picture set onto a plane that I show in the interface somehow. But since it’s a picture, how can I then find the circle outer bounds from the picture size? I’m guessing I have to know the exact size of the circle to perform some kind of raycasting and calculate the bullet spread right? Would it be easier to create some kind of circle object that has the correct proprieties and calculate a raycasting from it? Wild guessing here
if you put the circle graphic in a material, and place it on a plane or flattened cube of size 1, it's size will be 1.
Now you can use that to deter$$anonymous$$e the actual bullet spread - you don't need raycasts, just line equations. (raycasts are expensive!). So you can calculate how the bullets expand as they move outward. Your bullets will need colliders to effect a hit.
Aha okay I will try it out as soon as i can and get back here to you! Thanks!
Your answer
Follow this Question
Related Questions
Shooting exactly to the center of screen 0 Answers
How to aim at crosshair in a 2D game? 0 Answers
How to make gun shoot in the crosshair 0 Answers
weapon Spread 0 Answers
Shots don´t go forward 0 Answers