# I need a 'dynamic' crosshair?

 0 Normal crosshairs that are 2d images on the HUD are good, but dont work well because sometimes if you shoot close or far, the bullet doesnt shoot where the crosshair says it will, this is very frustrating and hard to bypass. I need some type of code that makes the crosshair move slightly to ensure that the bullet will hit where the crosshair is. A good example is in Half-Life: 2. If you aim down a hallway and then look at a wall right next to you, you will see what I mean. more ▼ asked Aug 03 '12 at 04:56 PM jjj51 1 ● 1 ● 1 ● 1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

1 answer: sort voted first
 0 I would it do this way: send a raycast through the middle of the crosshair never used this function to measure distances, but if this is right ( http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html ) , hit.distance will give you the lenght of the ray between you an the wall you are pointing at. use the length and a factor to spread the bullets in random direction around the middle of the hit use the same factor to scale your 2d-texture of your crosshair up and down more ▼ answered Aug 03 '12 at 10:58 PM RickTick 41 ● 7 ● 23 ● 26 I have no idea how, I am fairly new to Javascript. I know the basics Aug 04 '12 at 02:10 PM jjj51 When you know the basics, where is your first problem. Raycasting?function Update(){ var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hit : RaycastHit; var rayLength = hit.distance;This code sends a ray from your camera to your mouse.position a rayLength is then your distance. Aug 05 '12 at 08:03 PM RickTick add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
Your answer

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x236
x111
x61

asked: Aug 03 '12 at 04:56 PM

Seen: 648 times

Last Updated: Aug 05 '12 at 08:03 PM