Before updating to Windows 10 you may need to return your Pro license. More information here

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

avatar image

69 25 18 25

(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

avatar image

Peter G
18.7k 35 101 222

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



Answers and Comments



asked: Apr 27, 2010 at 07:03 PM

Seen: 1705 times

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