x


transform script

how would i write a transform.position script using Vector 3,, i already know how to do rotations but i have played around with the script and i cant find how to do it

more ▼

asked Apr 27, 2010 at 07:03 PM

tatty gravatar image

tatty
69 25 18 23

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You put in transform.position = Vector3() or you can put a Vector3 into other transform functions such as Translate(). Note below, you could also create a variable for a Vector3 and insert that into any of these places.

So it might say something like:

function Update () {
     //You can say Vector3.up for everyone of these, but for teaching 
     //purposes I wrote it out.

     //Also note you would only use one of these at a time or you would get
     //strange results.


     transform.position = Vector3(0, 1, 0); //places the object one up in world space.

     transform.position += Vector3(0, 1, 0); //more complicated.  moves the object up one meter per frame.

     transform.Translate(Vector3(0,1,0));  //same as above but using translate instead.

     transform.Translate(Vector3(0 , 1, 0) * Time.deltaTime);  // Same as above,
     //but each component of the Vector is multiplied by 1/FPS to create movement 
     //in meters per second.
}

The reference also has several examples of Vector3's to check out.

more ▼

answered Apr 27, 2010 at 07:19 PM

Peter G gravatar image

Peter G
17.6k 29 63 163

thanks this is really helpful

Apr 27, 2010 at 09:31 PM tatty

Im having trouble. Im trying to fire a bullet from a moving enemy.

So I instantiate the bullet at the enemies current position, but for some reason, my transform.Translate(Vector3(1,0,0)*Time.deltaTime);

sends the bullet in the negative X direction instead of positive. Is it because the enemy is moving?

Jan 24, 2013 at 05:21 AM Folio
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1023

asked: Apr 27, 2010 at 07:03 PM

Seen: 1547 times

Last Updated: Jan 24, 2013 at 05:21 AM