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 ?
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.
answered Feb 22 '15 at 07:53 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here