transforms, vector3's,moveDirections, and so on.

Hi guys and thanks for looking i am trying to understand all of these but i have no idea what they mean or where to start. I have been to the reference but i think it is a bit vague (No offence to anyone) could someone please help me understand all of these. The main reason i am asking is so that i can write a script for my enimies AI

I have everything else required for this game now it’s the enemies and it’s done. Well apart from updating the art and animations :slight_smile:

Please help guys

Thanks

John

The documentation is not at all vague if somebody is properly prepared with the appropriate level of knowledge for programming, physics, rendering, etc. The problem is that Unity creates a very low barrier of entry to making something, so it’s easy to get in over your head quite quickly.

A transform is positional data, basically where the object is and the direction its facing. It also includes the parenting relationships of which objects are attached.
A Vector3 is a value type of three floats. When used with a transform it can represent position in three dimensions or rotation in Euler angles. At its core, it’s just three floats and you can put whatever you like in each datum.

If you need help understanding more terms, post them. I’m not going to write a glossary here.

I don’t even know what you’re asking for.

Thanks JRavey lol

I understand it a bit more.

It’s just when people write in their code things like this i think WTF is that

function Awake()
{
animation["Walk"].layer =0;

}

var waypoint : Transform[];
static public var speed : float = 37;
private var currentWaypoint : int;
var loop : boolean = true;
var player : Transform;


function Update() {
		
	var distFromPlayer : Vector3 = player.position - transform.position;
	if(currentWaypoint < waypoint.length){
	
		
		var target : Vector3 = waypoint[currentWaypoint].position;
		var moveDirection : Vector3 = target - transform.position;
	
		var velocity = rigidbody.velocity;
		if(moveDirection.magnitude <1){
			currentWaypoint++;
		}
		else if (distFromPlayer.magnitude < 20){ // If we are close to the enemy

		velocity = Vector3.zero;
		target = player.position;
		velocity = (player.position - transform.position).normalized * speed;
		if((player.position - waypoint[currentWaypoint].position).magnitude > 50){
		target = waypoint[currentWaypoint].position;
		velocity = moveDirection.normalized * speed;
		}
	}
		else{
			velocity = moveDirection.normalized * speed;
			}
	}
	else{
		if(loop){
			currentWaypoint = 0;
		
		}
		else{
			velocity = Vector3.zero;
		}
		
	}
	
		rigidbody.velocity =velocity;
		transform.LookAt(target);
		
	
}

When in doubt, refer to the docs and also do a google search as most of these terms are used in other engines and systems.

A couple of things: firstly, reading someone else’s code is usually confusing, because most programmers of varying levels have very different ways of scripting things. A good thing to do is to break the code up for yourself.

First, look for the Monobehaviour states, like Awake(), Start(), and Update(). You should then have an idea of what is being initialized, what is being constantly updated, etc…
Next, read the names of the variables! The names of the declarations, especially in the code you provided, will give a good hint of what the variable function is going to be doing. Breaking down the if/while loops doesn’t get much more straightforward, so I won’t go into it.

Then, as already explained by JRavey, remember that transforms and Vector3’s are used to pinpoint the coordinates of an object in game space, be it local or world.

And uh, read the Scripting Reference. :slight_smile:

I’d also be more than happy to offer some insight but I need more specific questions (or at least narrow it down to one topic).

Traditionally in 3D software, a Transform describes an object’s space relative to another object (usually the parent (local) or the world (global)). A transform includes scale, rotation and position in a 4x4 matrix, which, thankfully you almost never need to work with directly. Unity doesn’t offer a transform as a separate object/matrix from a GameObject. They are one and the same. This can trip people up at first because you can’t copy a transform, do stuff and then write it back to the same object (or another one). You have to work with the position or rotation objects instead. SO… in Unity, when you want to work with an object’s position, you will be using myGameObject.position, which is a vector3 in the form of (x, y, z) coordinates. Which, as I mentioned above, is relative to another object (usually the parent (local) or the world (global)). So, the reason you can describe a vector with just a single coordinate, is because the first point of the vector is 0, 0, 0, so if you set a position to 0, 0 ,0, you will move the object to where its parent is (or the world origin if setting a global position).

That is the basics of all 3D. Hope it helps.

Jeese thanks guys still trying to get my head around it i know all about other things like int’s and bools and work with them greatly. But it’s the positioning of things that confuse the heck out of me. Also the things like magnitude and other confusing stuff i feel this is all i need to learn to be able to evolve my skills as a programmer and help understand alot of other concepts

Just continue posting.

Magnitude is just the distance between the two points which define the vector. Well it is actually the “length” of a vector, but same as really. A normalized vector is only one unit long, or a magnitude of 1, but still points from point A to/through point B. This is used a lot to determine physics force in a direction too.

Programming is part math, part logic and part practical knowledge. I feel that it’s necessary to mention that in this case.

Dreamblur has wisdom. Thankfully, the logic and the practical knowledge can be put to good use in learning the math concepts necessary. This isn’t elementary school, but then again, it isn’t exactly traditional algebraic functions either. Mind you, it can be (especially if you’re a physics programmer), but for now, all you need is to utilize the math functions written for you to control the transforms of your game objects.

Guys i really appreciate the help here thanks and i will start breaking the code down and see if i start to learn it all

Could someone please write an example of these things so i can see what it does. Because i am still finding it hard to understand all of this. Also once again thanks for taking the time to explain these things

Cheers

Johnessy

Please post a specific question about a single topic and some detail about what you are trying to do, and I’m sure you’ll get all the help you need. This subject is far to vague. Once you a specific problem to solve, it gets much easier to learn. My first Unity project was to make a turret that targeted and item and sent an “OnHit” message, for example.