Vector3 Constructors

:idea:
we are know well that Vector3 Struct has its own ‘Class Variables’ like ‘zero,one,forward,up.right’ and we can use it like that ’ vector3.forward, Vector3.up …etc’ how can i make my custom class variable for example called ‘p1’ and use it as ’ Vector3.p1 ’ I tried but I doubt that there is a wrong syntax, here is my skeleton code:

var p1 : Transform;

function Vector3.p1(x,y,z) {
x=p1.position.x;
y=p1.position.y;
z=0;
}

function FixedUpdate() {
rigidbody.AddForce(Vector3.p1);
}

I think what you are referring to is:

var p1 : Vector3 = new Vector3(x,y,z);

function FixedUpdate() {
rigidbody.AddForce(p1);
}

Or if you want it in a function, something like this:

// untested

var p1 : Transform; // p1 will need to be set to a valid transform for this to work

function getVector(trans : Transform) : Vector3
{
return(new Vector3(trans.position.x,trans.position.y,0));
}

function FixedUpdate()
{
var v1 : Vector3 = getVector(p1); // assuming p1 has been set to a value by this point;
rigidbody.AddForce(v1);
}

Thanks for posting twice … :wink:
The code nearest what I’m thinking in, but the first object don’t go exact to second object position, the right event is object1 define object2 position then go to it.

I reach the same result with this simple code:

var p1 : GameObject;
var p1p : Vector3;

function FixedUpdate() {
p1p=p1.transform.position;
rigidbody.AddForce(p1p);
}

Unless you’re using a language like Python then you can’t augment the existing class externally. Instead what you can do is make a derived class and add your new functions to that.

http://www.csharp-station.com/Tutorials/Lesson08.aspx

Alternatively you can build a function to do your bidding, another alternative in languages other than C# is the macro.

is this mean I can’t augment with javascript also…?

Not even with JavaScript, I’m afraid.