Jump to content
zagor64bz

[SOLVED]Random route to random destination?

Recommended Posts

Hi, what I basically wanna do is this: UNIT1 start from position "A" and have to go randomly to B or C or D across the map, possibly following, for each destination, a random route of 3 different waypoints "trail".

How do I do that?

Hope i was clear enough, thank you.

Share this post


Link to post
Share on other sites

What you want to do is to move the waypoints to empty markers (get pos, set pos stuff might work). I'm not a scripter though. Or you could just have the emprty marker positions and have script that adds a waypoint for the unit to that position. The waypoint would have on completion a script that creates a new waypoint in the next destination.

  • Like 1

Share this post


Link to post
Share on other sites
26 minutes ago, taro8 said:

What you want to do is to move the waypoints to empty markers (get pos, set pos stuff might work). I'm not a scripter though. Or you could just have the emprty marker positions and have script that adds a waypoint for the unit to that position. The waypoint would have on completion a script that creates a new waypoint in the next destination.

:thumb:

Share this post


Link to post
Share on other sites

So..is not possible to do that just with 3den editor? I cannot get a hang on this....anyone else wiling to help? I try searching on "random destination" but nothing really helpful...

Share this post


Link to post
Share on other sites

Hi

you could add some markers on the map then use code similar to below to addwaypoints for random route.

_route1 = ["rmarkerA1","rmarkerA2"]; // markers exist on map
_route2 = ["rmarkerB1","rmarkerB2"];

_routes = [_route1,_route2]; // two routes.

_routeIndex = round random (count _routes - 1);  // pick random route

_route = _routes select _routeIndex;
{
// make group moving by adding waypoints
_wp =_group addWaypoint [_x getmarkerpos , 0]; 
} foreach _route;

 

note I did not test the code I just quickly put it together. it should give you idea what to try. hope that helps!

 

(after picking the route from the markers you can delete the markers)

Edited by gc8
changed from floor to round command
  • Like 1

Share this post


Link to post
Share on other sites
2 minutes ago, gc8 said:

Hi

you could add some markers on the map then use code similar to below to addwaypoints for random route.


_route1 = ["rmarkerA1","rmarkerA2"]; // markers exist on map
_route2 = ["rmarkerB1","rmarkerB2"];

_routes = [_route1,_route2]; // two routes.

_routeIndex = floor random (count _routes - 1);  // pick random route

_route = _routes select _routeIndex;
{
// make group moving by adding waypoints
_wp =_group addWaypoint [_x getmarkerpos , 0]; 
} foreach _route;

 

note I did not test the code I just quickly put it together. it should give you idea what to try. hope that helps!

 

(after picking the route from the markers you can delete the markers)

Thank you bud....I'll test it and report back!

Share this post


Link to post
Share on other sites

Nope...not working.Give me this error:

18:23:23 Error in expression <routeIndex;
{

_wp =hvt addWaypoint [_x getmarkerpos , 0]; 
} foreach _route;


>
18:23:23   Error position: <getmarkerpos , 0]; 
} foreach _route;


>
18:23:23   Error Missing ]

 

Share this post


Link to post
Share on other sites
_wp =_group addWaypoint [_x getmarkerpos , 0];// wrong syntax

 

_wp =_group addWaypoint [getmarkerpos _x , 0];
  • Like 1

Share this post


Link to post
Share on other sites

Sorry guys...not working. Am I missing something?

Just to be clear, I have a unit in editor(hvt) and me,the player;

I put down the 4 markers:

A1&A2 going one direction,B1&B2 in the opposite (to simulate different routes)

I have a Radio trigger that execute the above script:

randomdestination.sqf

Quote

_route1 = ["rmarkerA1","rmarkerA2"]; // markers exist on map
_route2 = ["rmarkerB1","rmarkerB2"];

_routes = [_route1,_route2]; // two routes.

_routeIndex = floor random (count _routes - 1);  // pick random route

_route = _routes select _routeIndex;
{
// make group moving by adding waypoints
_wp =_group addWaypoint [getmarkerpos _x , 0]; 
} foreach _route;

Obviuosly, I try with 

_wp =hvt addWaypoint [getmarkerpos _x , 0];

No luck...what I'm doing wrong? Thank you!

Share this post


Link to post
Share on other sites
39 minutes ago, zagor64bz said:

No luck...what I'm doing wrong?


You need to add WP Type "MOVE"

 

_routes = 
[
	["rmarkerA1","rmarkerA2"],	// route A markers
	["rmarkerB1","rmarkerB2"]	// route B markers
];

_group = [getPos player, west, 5] call BIS_fnc_spawnGroup;

{
	_wp = _group addWaypoint [getMarkerPos _x, 0];
	_wp setWaypointType "MOVE";
}
forEach selectRandom _routes;

 

Share this post


Link to post
Share on other sites

It works..kinda. a group spawn on my position and move to random marker, but what I really want is the "hvt" to move...(with the spawned group is also ok..even better)

Share this post


Link to post
Share on other sites
33 minutes ago, killzone_kid said:


You need to add WP Type "MOVE"

You don't, not anymore. New waypoints are of MOVE type automatically.

Share this post


Link to post
Share on other sites

I made hvt to join the group and follow to random destination...is a workaround, but not what I really need.Damn.....

Spoiler

_routes =  
[ 
 ["rmarkerA1","rmarkerA2"],  
 ["rmarkerB1","rmarkerB2"]  
]; 
 
_group = [getPos hvt, east, 2] call BIS_fnc_spawnGroup;
hvt joinAsSilent [_group, 0]; 
 
{ 
 _wp = _group addWaypoint [getMarkerPos _x, 0]; 
 _wp setWaypointType "MOVE"; 
} 
forEach selectRandom _routes;

 

 

Share this post


Link to post
Share on other sites
37 minutes ago, theend3r said:

You don't, not anymore. New waypoints are of MOVE type automatically.

 

You're right, but it doesn't hurt to be explicit in this case.

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, zagor64bz said:

It works..kinda. a group spawn on my position and move to random marker, but what I really want is the "hvt" to move...(with the spawned group is also ok..even better)

You haven't given us all of your code.  If _group represents the group of hvt then the code would function as you desire.  Since you are spawning a group and _group refers to that, of course the waypoints are added to _group.  What you probably want is to run that script with _group assigned to "group hvt" and it will add the waypoints you want.  Sorry I can't be more explicit without seeing exactly the code you are running and exactly how you are calling it.

Share this post


Link to post
Share on other sites
38 minutes ago, dwringer said:

You haven't given us all of your code.  If _group represents the group of hvt then the code would function as you desire.  Since you are spawning a group and _group refers to that, of course the waypoints are added to _group.  What you probably want is to run that script with _group assigned to "group hvt" and it will add the waypoints you want.  Sorry I can't be more explicit without seeing exactly the code you are running and exactly how you are calling it.

Spoiler

/// lets name this "randomdestination.sqf";
////////////////////////////////////////


_routes =  
[ 
 ["rmarkerA1","rmarkerA2"],  
 ["rmarkerB1","rmarkerB2"]  
]; 
 
_group = [getPos hvt, east, 2] call BIS_fnc_spawnGroup;
hvt joinAsSilent [_group, 0]; 
 
{ 
 _wp = _group addWaypoint [getMarkerPos _x, 0]; 
 _wp setWaypointType "MOVE"; 
} 
forEach selectRandom _routes;

 

Code:

 

6 hours ago, zagor64bz said:

Sorry guys...not working. Am I missing something?

Just to be clear, I have a unit in editor(hvt) and me,the player;

I put down the 4 markers:

A1&A2 going one direction,B1&B2 in the opposite (to simulate different routes)

I have a Radio trigger that execute the above script:

 

0= []execVM "randomdestination.sqf"; on a radio trigger just for testing.

 

What I need is:

hvt is editor placed unit;

a trigger fire;

hvt follow a  route to a destination randomly choose from 3 different one.

 

Thank you dwringer 

Share this post


Link to post
Share on other sites
7 hours ago, dwringer said:

You haven't given us all of your code.  If _group represents the group of hvt then the code would function as you desire.  Since you are spawning a group and _group refers to that, of course the waypoints are added to _group.  What you probably want is to run that script with _group assigned to "group hvt" and it will add the waypoints you want.  Sorry I can't be more explicit without seeing exactly the code you are running and exactly how you are calling it.

 

I think dwringer has basically said what you need to do.

Change this:

_group = [getPos hvt, east, 2] call BIS_fnc_spawnGroup;
hvt joinAsSilent [_group, 0]; 
 
{ 
 	_wp = _group addWaypoint [getMarkerPos _x, 0]; 
 	_wp setWaypointType "MOVE"; 
} forEach selectRandom _routes;

To this:

{ 
 	_wp = (group hvt) addWaypoint [getMarkerPos _x, 0]; 
 	_wp setWaypointType "MOVE"; 
} forEach selectRandom _routes;

Didnt test it but should work.

Share this post


Link to post
Share on other sites

Start at A

 

Waypoint 1
Give a waypoint: MoveWaypoint –Waypoint Transformation
Placement radius 200
Completion Radius 25.  

 

This because the waypoint might be over a big rock or a building or something that you cannot reach. When you are within 25 meters you have completed the waypoint.

Also select Waypoint Visibility and tick both Map Visibility and Scene Visibility.


Do the same for waypoints 2, 3 and 4.  

 

Waypoint 5 would be your destination
Placement radius 0
Completion Radius 25.  

When ever you start the mission  you will follow a random set of waypoints.

 

For my next post I will describe a random start location AND a random set of waypoints.

.

 

 

Share this post


Link to post
Share on other sites

Could always do it like this... branching waypoints do not have to have the branches, just from the start you could chose from each civ and just copy its waypoints for a different route.

  • Like 1

Share this post


Link to post
Share on other sites

The script plot the route to destination using roads.

  • Where possible, will use the road with the best coverage: asphalt, then gravel, then mud and any terrain.
  • Script is not plot entire route at once, and, to distribute the computation, returns after each call coordinates of the next waypoint.

Call agruments:

  • currentPosition
  • destinationPosition
  • roadTypePrefixesArray
  • roadTypePrioritiesArray

Return value:

  • nextWaypointPosition

 

Usage:

private _nextWaypointPosition = [_currentPosition, _destinationPosition,
	["asf1_", "asf2_", "asf3_", "city_", "invisible", "grav_", "mud_", ""],
	[4, 4, 3, 3, 3, 2, 2, 1]] call SearchNextWaypointPosition;

 

SearchNextWaypointPosition = {
	params ["_org", "_dst", "_rts", "_rws"];
	private _rad = 50;
	private _dsc = _org distance _dst;
	private _cls = 0.000000000001;
	private _dss = _dsc;
	private _rdd = objNull;
	
	while {_rad = _rad * 2; isNull _rdd and {_rad <= 800}} do {
		{	private _rdt = getModelInfo _x select 0;
			private _clx = {if (_rdt find _x >= 0) exitWith {_rws select _forEachIndex}; 0} forEach _rts;
			if (_clx >= _cls) then {
				private _dsx = _x distance _dst;
				if (_dsx < _dsc and {_clx > _cls or {_dsx < _dss}}) then {
					_cls = _clx; _dss = _dsx; _rdd = _x}}} forEach (_org nearRoads _rad)};
	if (isNull _rdd) then {_org getPos [_dss min 800, _org getDir _dst]} else {getPos _rdd}
};

 

  • Like 2

Share this post


Link to post
Share on other sites

Great discussion giving different options for a common problem.  I used multiple marker arrays to represent multiple paths for AI to search Mabunga Swamp for camps.  AI controlled groups would be randomly assigned one of the the search arrays.  This was good for grid searching a large area.

 

But for random paths with a different destination I really like @Larrow's branching waypoints idea.  It's simple and easy to use with the visual eden editor.  Easy to drag and drop, and you can add more randomness to each waypoint with placement radius.

 

@serena's script is also very interesting for plotting fastest routes using roads.

 

Note that when you have waypoints far apart (>50 meters?), AI will favor roads.  But sometimes you want AI to not deviate and move straight to next position.  For that use case I built JBOY Calculate Intermediate Position to force AI to move more directly to next position.  This would not work well with Larrow's branching waypoints, but it does work well with using an array of markers or positions as a path.

  • Like 2

Share this post


Link to post
Share on other sites

THANK YOU ALL!!!

All good inputs, that I will try out...

 

As much as I don't like to, I have to unveil EXACTLY the purpose of this:

 

in a SP mission, I have an HVT that will escape capture from a raided ( by You, the player) HQ. He's wounded..bleeding..but,never the less, on the move.

Using the fantastic JBOY-DOG script your battle buddy Boomer will track down the HVT to his final destination.

Now, just for re-playabilities purposes, would be nice if each time you play the mission the final destination of the HVT is randomly chosen from an array of,lets say, 3 or 4 locations. That's why I need/would like to to do this.....

ps: Jboy...sorry to ask this here..will the dog track it down with a random set of waypoints?

  • Like 2

Share this post


Link to post
Share on other sites
48 minutes ago, zagor64bz said:

ps: Jboy...sorry to ask this here..will the dog track it down with a random set of waypoints?

Yes.  Start the script that creates scent markers on the HVT, and he will be tracked wherever he goes.  The scripts knows nothing about the tracked unit's waypoints, it simply creates a trail wherever the unit goes based on current unit position.

  • Like 2

Share this post


Link to post
Share on other sites
6 minutes ago, johnnyboy said:

Yes.  Start the script that creates scent markers on the HVT, and he will be tracked wherever he goes.  The scripts knows nothing about the tracked unit's waypoints, it simply creates a trail wherever the unit goes based on current unit position.

:thumb: Brilliant....

 

Share this post


Link to post
Share on other sites

Larrow solution ended up to be the more suitable:simple,no script, multiple choices.. Thank you Larrow and thank you all!

 

Ps: Arma is like my job (I'm a Chef)..you never,ever,stop learning..thank you all....

  • Like 3

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×