Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by Mazze · Jun 06, 2011 at 06:32 PM · positionobjecttranslate

Translating an object to another position, help!

Hey!

Now this is supposed to be very easy, done it with OpenGL and I don't get what i'm doing wrong.

So I have this object with its coordinates given on the UI (world coordinates??) and I have another set of coordinates in which the object should be on after an event. Also these coordinates were acquired using the editor and just reading the coordinates on the UI. So how should it be scripted, which one of the rows below is the right way?

 transform.Translate(X,Y,Z); //Realtive change?, what should the coordinates be?;
 transform.position = Vector3(X,Y,Z); //This doesnt work either, probably because I dont know much of the basics

Also saw some TransformDirection and InverseTransformDirection but i'm guessing those are used for changing between spaces..

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by testure · Jun 06, 2011 at 06:39 PM

personally, for something like this I just Mathf.SmoothDamp (or Vector3.Slerp) and handle the position change manually.

void Update() { transform.position = Vector3.Slerp(transform.position, desiredPosition, speed * Time.deltaTime); }

Comment
Add comment · Show 6 · 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 Mazze · Jun 06, 2011 at 06:42 PM 0
Share

So the "desiredPosition" would be the acquired one from the UI?, Tried that before and i just can't get it to change position. Don't need any interpolation or keyframe animation either.

avatar image Mazze · Jun 06, 2011 at 06:54 PM 0
Share

Guess it was this I was looking for: "It is worth pointing out that the Transform values in the Inspector of any Child GameObject are displayed relative to the Parent's Transform values. These are also called the Local Coordinates. Through scripting, you can access the Global Coordinates as well as the Local Coordinates."

avatar image testure · Jun 06, 2011 at 06:54 PM 0
Share

acquired from the UI? no.. you'd script it in whatever way you needed.. IE: player input, or external motivation.. whatever you need. or i guess you could acquire it from the UI but I don't see much point in that.

if you don't need interpolation, then just set transform.position to whatever Vector3 you want. It'll move instantly and you're done.

avatar image Mazze · Jun 06, 2011 at 08:45 PM 0
Share

But that is the point! it wont get to the position I want to and I wonder why is it so

avatar image testure · Jun 06, 2011 at 08:48 PM 0
Share

in your update function, if you (for example) add:

transform.position = new Vector3(20f, 10f, 15f);

and it doesn't move- then you have a problem somewhere else in your code. manually changing the position of your game object in script automatically takes precedence over everything else- including UI input. If you still can't get it working using the information I've given you, post your full script so we can see where the problem is.

Show more comments
avatar image
0

Answer by ramp · Dec 27, 2012 at 10:23 AM

What you are looking for is something like: transform.position = Vector3.Slerp(transform.position, gameObje.transform.position, 5 * Time.deltaTime);

Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Position Error in p30 lite - android 10 0 Answers

how to set rotation / position of an object on trigger? 2 Answers

How do I translate around a circle? 3 Answers

Stop moving at the target position by using Vector3.forward 0 Answers

2D get touch input 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges