x


need help with raycast

I am trying to use this raycast for creating some kind of laser in my space game. But it is not working, what do i have to correct?

 if (Physics.Raycast(transform.position, new Vector3(transform.position.z - Aim.position.x,
transform.position.y - Aim.position.y,
transform.position.z - Aim.position.z), out hit,200))
                  {

                       Debug.DrawLine(transform.position, hit.point, Color.green, 1, false);
                       try
                       {

                     hit.collider.gameObject.GetComponent<Energy>().power -=3;
                       } catch
                       {
                       }
                            try
                       {
                       hit.collider.gameObject.GetComponent<health>().hp-=1;
                       }
                       catch
                       {
                       }


                   }
more ▼

asked Sep 08 '12 at 12:59 PM

ehnaton gravatar image

ehnaton
84 4 6 10

nobody knows what's problem with this script?

Sep 08 '12 at 01:22 PM ehnaton

could you click EDIT and tidy it up ? the first line is way way too long, make it a few lines

Sep 08 '12 at 01:50 PM Fattie

done. now the solution

Sep 08 '12 at 01:52 PM ehnaton

Should 'transform.position.z - Aim.position.x' be 'transform.position.x - Aim.position.x'?

Sep 08 '12 at 02:14 PM FlyingOstriche

thanks, but it is still not working....

Sep 08 '12 at 03:10 PM ehnaton
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

thanks to all, the problem was solved. It were just my curved hands. Sorry for disturbing, the script is working perfectly.

more ▼

answered Sep 08 '12 at 03:25 PM

ehnaton gravatar image

ehnaton
84 4 6 10

(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:

x3735
x1528

asked: Sep 08 '12 at 12:59 PM

Seen: 150 times

Last Updated: Sep 08 '12 at 03:25 PM