Nearest walkable position inside a region

Is it possible to determine “nearest walkable position” value inside a certain region?
For instance, inside a sphere with constant radius of 10 which is located at vector 0.0.0
Here’s a screenshot of how it would look like: imgur. com/a/ojhwa8t (the center of the green ring represents the neareast walkable position)

Sorry If I expressed my thoughts incorrectly, but the thing I wanted to do is to get the workshop to define nearest walkable position (to a player who is outside the sphere) which is located strictly inside the sphere (not just the center, because in my case if I set Neareat walkable to a vector of (Global.A), then it will always return Global. A because of the sphere’s position, so I want it to be nearest to the player, but with the “filter” of being inside the sphere) via certain filters or values (which I don’t know of, given “filtered array” is even appliable to “nearest walkable position”), so I could just TP a player to this position.
Here’s what I came up with: CSJWX
If I press interact while being outside the sphere, it sets the player variable to the center of the sphere (which isn’t supposed to happen, given that there are a lot of walkable positions inside the given coordinates aside from the center), however, If I step inside the sphere, the filter works correctly.

So you want the Position of a Player or suitable position,preferable an Array of Positions, it needs to be inside a radial/circular/spherical region, it should not be the center of that sphere and it should be walkable determined with Nearest Walkable Position, right? Or do you just want to check if the given positions are Walkable and inside the region? As far as i know the Nearest Walkable Position value has a built-in check and functionalities that likely scan the Maps we play on and figure out if these positions are reachable by any means. But its soley not possible to reproduce that easily in workshop, we can just retrieve the nearest walkable position by that, but with Distance Between we can create something like an overlap of vectors to tell if something is inside a sphere outside a sphere or at the sphere.

1 Like

the Position of a Player or suitable position,preferable an Array of Positions, it needs to be inside a radial/circular/spherical region, it should not be the center of that sphere and it should be walkable determined with Nearest Walkable Position

Yes, this is what I was trying to say this whole time (sorry, I can’t really explain anything properly when it comes to coding). Though only one position is enough
Here are some screenshots of what I want to happen in case my speech gets confusing again: imgur. com/a/rHVWWdK
The first one - I’m in a random position and press F - the position is defined and is showed by the center of the green ring
The second one - I change my position
The last one - I press F again and repeat the process described in the first one

Well that requires a bit of math, i would need to know the frequence of how many positions you need or should be in that Sphere, we can not gain any possible points from a sphere with one action, but generate them within a sphere and check if these are walkable, thats how i would to it. Do you have any vision of how many, two main positions, 10 positions around the center but a random offset where the max offset has the length of 10m so they are still within the sphrere, something like that, then it should be possible, but may look randomly.

1 Like

Here is an example, well it doesn’t require that much math which would invovle two angles to generate the position in sphere, i use Random Real and inbound, outbound offsets to generate 10 Position idk how many are needed or what your game mode will look like in the end. But you can teleport randomly(currently maybe you want a selector to specify one position, tell me if so) to one of these and Nearest Walkable Position takes care of the rest here is the example code:

variables
{
	global:
		0: Center
		1: Effect
		2: PositionInSphere
		3: Positions
}

rule("Rule 1")
{
	event
	{
		Ongoing - Global;
	}

	actions
	{
		Global.Center = Vector(0, 1, 0);
		Create Effect(All Players(All Teams), Sphere, Color(White), Global.Center, 14, Visible To Position Radius and Color);
		Global.Effect = Last Created Entity;
		For Global Variable(I, 0, 10, 1);
			Global.PositionInSphere = Vector(Random Real(Random Real(-14, -1), Random Real(1, 14)), Random Real(0, 1), Random Real(Random Real(
				-14, -1), Random Real(1, 14)));
			If(Distance Between(Global.PositionInSphere, Global.Center) <= 14);
				Global.Positions[Global.I] = Global.PositionInSphere;
			End;
		End;
	}
}

rule("Rule 2")
{
	event
	{
		Ongoing - Each Player;
		All;
		All;
	}

	conditions
	{
		Is Alive(Event Player) == True;
		Count Of(Global.Positions) != Null;
		Is Button Held(Event Player, Button(Interact)) == True;
	}

	actions
	{
		Teleport(Event Player, Nearest Walkable Position(Random Value In Array(Global.Positions)));
	}
}

Feel free to ask any further questions, sorry for the late reply but meanwhile i was setting the code up, i encountered a bug with the Continue directive/action that i used in the for-loop of the code, i just removed that critical part for now. Anyways hope that is what you need have a nice day :slight_smile: .

2 Likes

You can use a random position inside your sphere by using

code

Global.CenterOfTheSphere + Vector(Random Integer(-1 * Global.Radius, Global.Radius), Random Integer(-1 * Global.Y, Global.Y), Random Integer(-1 * Global.Radius, Global.Radius))

Here Global.CenterOfTheSphere is the coordinate of the sphere (center) position, and Global.Radius is half the sphere’s diameter. Then you can apply “Nearest walkable position” to the resulting vector. Global.Y can be changed or equals 0… whatever.