Moving the Masses

posted in the game for project unirule
Published September 23, 2018
Advertisement

I'm very pleased to showcase the new functionality I've incorporated allowing the user to select many Simulin at once.
This feature was always on the back-burner because there were more pressing things to address.  I'll quickly go through the technique I used.

But first, please watch the following videos! :) 

 

 


I created a two faced plane where the opposite corners are defined by the vertices obtained from the right-click down and up events.  Then raycaste to the planet twice and I have all four corners for the plane.  After that I normalized the vertices and then raycaste from the position of every visible Simulin to the center of the planet.

It's not 100% perfect, because the perspective camera obscures things a bit and the box that is drawn is an html element.  For this reason Simulin along the edges of the selection box will sometimes not be selected.  But really?  big deal...

Once the target Simulin are identified the user selects the destination.  This is where the scripted behaviour of the Simulins movement comes in.  Rather than having all the Simulin converge on a single point I created a move-able plane whose vertices are defined in a spiral 


initilizingFunction.definePositionPlane = function( unitScale ){ 

	var geometry = new THREE.Geometry();
	var material = new THREE.MeshLambertMaterial( { side: THREE.DoubleSide } );

  	// 'qv(0,0,0)' is short form of 'new THREE.Vector3( 0,0,0 )'
	geometry.vertices.push( qv( 0 , 0 , 0 ) );
  
  	/* the following function creates an 11 x 11 grid of vertices.
  	* the first vertices is located at the center of the grid.
  	* if we were to number the vertices 1 through 121 left from right, up to down
  	* then the first vertices defined would be at the position of the 61st spot in the grid.
  	* as the function cycle through 'i', two 'n' loops of 'l' length add move the location 
  	* of the next declared vertices 'l' left/right depending and 'l' up/down depending.
  	* at the end of both 'n' loops l is incremented and the directions toggle.
  	*/
  
	for( var i=0, j=61, k=61, l=1, q=-1, p=1, b=15; i<121; i+=0 ){
		if( l < 11){

			for( var n=0; n<l; n++ ){
				j += q;
				geometry.vertices.push( qv( ( j - 61 ) * u * b , 0 , ( k - 61 ) * u * b ) );
				i++;
			}
			for( var n=0; n<l; n++ ){
				k += p;
				geometry.vertices.push( qv( ( j - 61 ) * u * b , 0 , ( k - 61 ) * u * b ) );
				i++;
			}
			q*=-1;
			p*=-1;
		
			l++;
		} else {
			for( var n=0; n<10; n++ ){
				j += q;
				geometry.vertices.push( qv( ( j - 61 ) * u * b , 0 , ( k - 61 ) * u * b ) );
				i++;
			}
			i = 121;
		}
	}

	var face = new THREE.Face3( 0 , 10 , 120 );
	geometry.faces.push( f );

	face = new THREE.Face3( 0 , 120 , 110 );
	geometry.faces.push( f );

	geometry.computeFaceNormals();

	var mesh = new THREE.Mesh( geometry , material );
	mesh.visible = true;

	return mesh;

};

The plane is moved and then oriented over the point the user chose.  Each Simulin requesting a path is given an incremental vertices obtained from the selection plane. A raycaste call is done from that vertices location once the vertices is extrapolated to its global position.  From there I get the sphere position and that become the unique goal for the Simulin in question. 

I think the effect looks awesome.  

Right now you draw the selection box by holding down the right mouse button and then when you release it the calculations are done.

I'm also thinking that in the future I can program a custom routine and color for the direction in which you draw the selection box.   If you go left to right, up to down then maybe you select every Simulin.  right to left, up to down then maybe you select only hunters or some such idea.

Let me know what you think....

4 likes 1 comments

Comments

Awoken

Things are progressing a little faster than I had thought.  There were a lot of loose ends that needed to be addressed and they were taking forever, ( my last robust challenge as the perfect example ) 

Some updates I've made recently are:

- when the terrain of the planet is manipulated in one client browser and a new client browser is opened, the changes to the terrain are reflected. ( I still have to push a change to existing client browsers ).
- when the terrain is changed the path-finding server reflects those changes.
- what I call 'foundation plates' can be made now.  In the video they're 5 units high, so about as high as a Simulin, the height is arbitrary, but just to give some reference.

Foundation Plates
All dynamic buildings that are made will have to be built on top of a foundation plate.  Simulin will be able to walk on the surfaces of foundation plates.  Foundation plates will be stack-able.  If a foundation plate is 1 unit high it's basically an elaborate 'step' and the Simulin will be able to directly step onto it and travel across it.  If however, the plate is higher than 1 unit then the Simulin will have to travel around the plate using path-finding nodes.  If you want the Simulin to step up on to a tall foundation plate you'll need to provide steps for them, the dynamic steps will be programmed later. 

Dynamic Structures
The purpose of all this is so that you can build some cool ancient structures such as the Parthenon, Pyramids and the Ziggurat of Ur and have your Simulin walk in and around them path-finding around walls and stuff, going threw doors and archways.  But Really you could build what every you wanted to, basically what ever the dynamic asset creation tool will allow.

In the video the structures just pop into place once you select the points.  When the simulation is running however, the Simulin will have to build the structure first before they can interact with it.  The volume of 'material' will have be calculated and collected by the Simulin.  Of course any Simulin you assign to the task will need to be rewarded for their efforts, be fed and sheltered.

Once the structure is finished I intend on having the structure provide what ever modifiers you had chosen.  So is it a spiritual structure? storage space, rest area, teaching area and so on...

There will be pre-defined structures that will be pre-loaded, dynamic structures that I'll create and add to the game.  If a user wants to build a house they can choose a pre-defined template or create their own. 

I've got the farmer's role figured out for the early game and just what the farmer can and can't do, build and can't build.  There is so, soo much more to this idea and how it's all going to work, but I'll save it all for other times.
I'm getting excited, this games going to be awesome!

Have a great weekend

[ 07/10/18 ]
Oh very cool, now when one client window makes changes to the terrain the changes are broadcast to all connected clients. :) 

October 06, 2018 09:22 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement