x


Shoot A Raycast At A Specific Location?

Hello,

I want to be able to shoot a raycast from an objects transform (helicopter_gun) to a specific location.

That specific location is set by the user.

So, heres how it works:

The users clicks anywhere in the scene (using raycast from camera), that position of that click is then sent to the helicopter gun, and then that starts raycasting from itself, to that clicked position.

How would that be done?

So to save location of clicked area in scene, I'm thinking something like:

var savedLocation;
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
Physics.Raycast (ray, hit, 600, layerMask);
//something like: savedLocation = hit?
(with a if(Input..fire1 - in there somewhere)

Helicopter:

Physics.Raycast (transform.position, savedLocation, 10)??

This is just a rough outline - but if you could give me some idea - then that would be great.

Cheers

--EDIT --

I was also thinking that maybe - where the user clicks, a GameEmpty is initiated, and then the helicopter raycast could then use that as a 'track'

more ▼

asked Apr 04 '11 at 09:58 PM

oliver-jones gravatar image

oliver-jones
2.5k 205 225 253

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

1 answer: sort voted first
more ▼

answered Apr 04 '11 at 10:02 PM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

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

x1528
x885
x225
x193
x80

asked: Apr 04 '11 at 09:58 PM

Seen: 1257 times

Last Updated: Apr 04 '11 at 09:58 PM