• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by sam · Dec 13, 2010 at 12:53 AM · transform

translate ..... .. .

I want to translate a game object from one position to another at speed v and then return to its original position at speed v/2 and then repeat everything again (just like a back and forth movement).Any help would be greatly appreciated?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessy · Dec 13, 2010 at 01:13 AM 0
Share

Why did you post this AGAIN? http://answers.unity3d.com/questions/31438/transform-position

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Rydrako · Dec 13, 2010 at 01:21 AM

You Should do something like this -

var speed = 5;

function Update () {

//This will check if your object's position is (0,0,0).

if(transform.position == Vector3(0,0,0)) {

   //Lets move your object.

   transform.Translate(speed * Time.deltaTime,0,0);

}

//This will check if your objects position is (10,0,0).

if(transform.position == Vector3(10,0,0)) {

//Lets move your object back but slower, like you want.

transform.Translate(-speed/2 * Time.deltaTime,0,0);

}

}

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Rydrako · Dec 13, 2010 at 01:22 AM 0
Share

Plus I actually don't know how to correctly enter code. . .

avatar image oliver-jones · Dec 13, 2010 at 01:28 AM 0
Share

All you do is highlight all your code, then press the 0101 icon

avatar image Rydrako · Dec 14, 2010 at 12:00 AM 0
Share

Thank you for telling me that, anyways did that code help you?

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How can I access the children of a Transform? 5 Answers

Trying to make an object "Flee" from the player but it won't work? 3 Answers

EulerAngles value as floating point 1 Answer

Move Parent Along Childs Local Axis 1 Answer

can't use camera position in equasion, help! 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges