Line in Unity 3d – Vectrosity 1.4 Tutorial 1

Vectrosity 1.4 is out !
Congrats to all who bought it. It is a very solid packet.
If you start with Vectrosity now, here is a small walkthrough with various tips and tricks.
Start by importing VectrosityDemos_Unity3.unitypackage in an empty project.
In the Project view open the scene _Simple2DLine located in Vectrosity ->_Scenes.
You see nothing in the scene editor and it is ok. In the Hierarchy view select Main Camera.
In the Inspector view you will notice that besides the usual camera stuff there are 4 extra scripts, from which the one called Line is checked.
Lets hit play… Ta-ta ! A beautiful line appears across the scene ! Wait… It is kinda jaggy. Where are those nice lines you expected ?
Lets open the script. Pretty explanatory really.
At line 8 it states ” // Make a VectorLine object using the above points and the default material, with a width of 2 pixels”
Default material results in jaggy lines. Lets change this.
We will use the following variant of VectorLine:
VectorLine (name : String, points : Vector2[] or Vector3[],material : Material, lineWidth : float, lineType : LineType = LineType.Discrete, joins : Joins = Joins.None)
It is documented in the Vectrosity Reference Guide.pdf that comes with Vectrosity. This variant allows as to add a material.
Lets change the script to

var myMat:Material;
function Start () {
	// Make Vector2 array; in this case we just use 2 elements...
	var linePoints = [Vector2(0, Random.Range(0, Screen.height)),				// ...one on the left side of the screen somewhere
					  Vector2(Screen.width-1, Random.Range(0, Screen.height))];	// ...and one on the right

	// Changed null to myMat so we can choose a material in the inspector, width to 4.0 from 2.0.
	// Method signature: VectorLine (name : String, points : Vector2[] or Vector3[], material : Material, lineWidth : float, lineType : LineType = LineType.Discrete, joins : Joins = Joins.None)
	var line = new VectorLine("Line", linePoints, myMat, 4.0);

	// Draw the line
	Vector.DrawLine(line);
}

Now assign in the Inspector the material called VectorLine in the MyMat slot.
Save scene, press play and you havea nice, anti-aliased line :)
If you like this kind of lines, make sure that you use the VectorLine material.

This entry was posted in Uncategorized by ippo. Bookmark the permalink.

Leave a Reply