x


I need a 'dynamic' crosshair?

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 gravatar image

jjj51
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I would it do this way:

  1. send a raycast through the middle of the crosshair
  2. 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.
  3. use the length and a factor to spread the bullets in random direction around the middle of the hit
  4. 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 gravatar image

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
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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