Could you draw a image of how you expect it to look because this image gives the wrong impression
Not sure how your going to spawn items behind the player when the camera is zoomed out
Could you draw a image of how you expect it to look because this image gives the wrong impression
Not sure how your going to spawn items behind the player when the camera is zoomed out
If the camera is zoomed out and there is no space for the position to be generated, I want the function to just return nil.
Let’s say the camera is only zoomed out a bit but there is only a small area remaining that is possible for the part to spawn should it still have a 100% chance of spawning or would there be a random chance it returns nil?
It should have a 100% chance of generating a position unless there is absolutely no space for it to generate, then it should just return nil.
If we imagine the green dot is the player and the red dot is the camera you want to spawn a part within the purple area that will be a bit expensive and we will have to loop and measure all points that fall within the purple part and select one at random
But if you don’t mind it would be easy to spawn a part within the orange circle so would you be happy with spawning parts in the orange circle only or do you want the expensive method of spawning in the purple area?
Preferably I would like to have the function always return a position unless there is no space. I want to limit the random angle to always be outside the player’s FOV.
local angle = math.random() * 2 * math.pi
So the variable above would always return an angle outside the player’s FOV.
local angle = math.random() * (math.pi * 2 - fov) - math.pi / 2 + fov / 2
Something like this would work, but it does not take being in 3rd person into account.
Is the image I sent above correct you want the part to spawn inside the purple area? Or is it be a radius around the camera?
I would like the position to be generated inside the purple area.
So the circle radius is measured from the character where the fov position is measured from the camera
Because if the radius was measured from the camera then all you would do is change characterCFrame
in my demo project above to use the cameras CFrame instead
Yes, the radius is measured from the character, not the camera.
And do you want it to be flat like a pancake like in the demo project or do you also want it the have a random angle on all 3 axis?
The area should be flat like a pancake
Ok so first thing your going to need to do is generate dots around the character like this
Then we have to loop each dot to see what ones are not inside the camera field of view
Then we are going to select one from random
Then we are going to select a random position between the camera and the dot
One problem is that this will give a higher change that the random position will be closer to camera and not evenly distributed
If we want it to be evenly distributed then we need to generate points like this
Then we loop every dot to see if they are outside the camera field of view then we select 1 dot at random
Another option is to just keep generating a random location every time and keep doing it over and over again untill it falls out side the camera fov the perform of this is random as we don’t know if it will find a position on the first attempt or after 1000 attempts
But is it neccesery to generate a bunch of points and then loop through each of them and check if they’re inside the FOV? Would it not be possible to generate a position with one line of code. Using some formula to do all of this for us?
I’m not sure if your game is first person, however if it’s not, you also might want to consider the player zooming out to get a wider view.
That’s what I’m trying to do. Make it so the generated position always is out of view.
I just did a test, which I zoom in and out while printing the workspace.CurrentCamera.CFrame
and it seems to be directly related (to be expected), you can take this a lead and perhaps work to teleport this NPC behind the player’s camera, this might save you some time.
No, I can’t do that because there might be something obstructing the player and a generated position directly behind the player. Also, It would be very predictable.
I can’t think of any easy way to do this then, however there are two option which I can think of:
I know the most convenient would be the second choice as it lets the player actually have some challenging gameplay, however the easiest in my opinion would be just to lock zooming which would make your work a handful easier.
I agree that the first option would be the easiest, and I might just have to go with it. But preferably I would like the second option, so I will continue researching for a method of doing it that way. Anyways, thank you for helping