Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How Do You Raycast At A Random Location In Area


I know how to raycast from the center of the camera, but how would you raycast in a random place on the screen in an area.

To explain further I am making a shooter game and I want for there to be a blueprint for if you do not zoom in and use the scope on your gun, you will shoot in a random place on the screen but in a confined space.

like in this picture http://i.ytimg.com/vi/S0780E8mBpQ/maxresdefault.jpg

Unless you zoom in you will shoot anywhere in the white diamond . How would I make that using blueprint? Also would i make the white diamond in blueprint or in Umg? and how ?



Product Version: Not Selected
more ▼

asked Feb 22 '15 at 06:18 PM in Blueprint Scripting

avatar image

16 5 6 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

The cross-hair has to be done in UMG or at least the HUD.

Basically you have your trace from the center of the camera straight forward. I'm not sure how exactly you do it but one can just get the forwrad vector and multiply it with some distance. Now to have it not exact but randomized you have to rotate that vector a bit from it's default angle to a random one between your points.

First I would get a random float between -1 and 1, then multiply it with the maximum angle it should spray away from the default location and rotate your raycast by that value. Since this maximum spray number can easily be a variable you can increase it the longer one shoots. You can also provide it to your UMG to set the size of your diamond there.

Now getting the right numbers here will take quite a bit of try and error. Also properly rotating the raycast is a bit of vector math but it should be reasonable to get working.

I hope this helps.


more ▼

answered Feb 22 '15 at 07:53 PM

avatar image

5.9k 291 86 293

avatar image MikhailPK Feb 23 '15 at 02:58 AM

I still do not fully understand how to rotate the raycast and make it spray anywhere, could you possibly show me how to do it via blueprint?

Thanks, Mike

avatar image Erasio Feb 23 '15 at 10:32 AM

Well generally that's vector math but Unreal even provides a function called "Rotate vector". You just have to input your angle and it rotates it accordingly.

There really isn't much to it.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

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

Answers to this question