Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Assessedgrub · Feb 05, 2013 at 04:01 PM · c#transformmove

C#: Move a gameobject from a random location?

Hi I have a game object that spawns at a random location on the Y axis and moves along the X axis. Is there any way I could make it move(travel there, not just appear) to a specific XYZ location when it its a certain point on the X axis?

Any help would be greatly apreciated :)

Comment
Add comment · Show 6
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 Landern · Feb 05, 2013 at 04:04 PM 0
Share

Have you considered using iTween(free in the asset store)? It will do all the math for you and this is a common usage.

avatar image Assessedgrub · Feb 05, 2013 at 04:08 PM 0
Share

Thanks, I'll check that out now.

avatar image Assessedgrub · Feb 05, 2013 at 06:37 PM 0
Share

I have tried to figure it out, but have no clue as of how to get it working.

             iTween.$$anonymous$$oveTo(gameObject, Vector3(2,0,0), 3);

I put this where I want it to happen in the script attached to the gameObject but I get this error message:

Expression denotes a type', where a variable', value' or method group' was expected

Anyone got an idea how I should set it up properly?

avatar image robertbu · Feb 05, 2013 at 06:44 PM 0
Share

This is a frequently asked question. In addition to iTween, take a look at $$anonymous$$oveObject. And to code it yourself, you will find numerous examples if you search this list for 'Lerp' or '$$anonymous$$oveTowards'.

avatar image robertbu · Feb 05, 2013 at 07:45 PM 0
Share

You need a new before Vector3().

 iTween.$$anonymous$$oveTo(gameObject, new Vector3(2.0f, 0.0f, 0.0f), 3.0f);
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hoy_smallfry · Feb 05, 2013 at 07:55 PM

http://en.wikipedia.org/wiki/Linear_interpolation

Psuedo-code (to give you the idea):

 function start()
 {
     timeElapsed = 0
     startPoint = the game object world position
 }

 function move_to(Vector3 targetPoint)
 {
     timeElapsed = 0
     endPoint = targetPoint
 }

 function update()
 {
     if timeElapsed < totalMovementDuration, then
     {
         durationInterval = timeElapsed / totalMovementDuration
         game object world position = linear interpolate (startPoint, endPoint) with durationInterval
     }
     else
     {
         startPoint = the game object world position
     }
     timeElapsed + Time.deltaTime;
 }

Unity has Vector3.Lerp() function for linear interpolation, try it out.

Comment
Add comment · Show 1 · 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 Assessedgrub · Feb 06, 2013 at 03:33 PM 0
Share

Thank you, robertbu's comment helped, but I'll be checking this out too :D

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i set a radius for rotatearound ? 0 Answers

Multiple Cars not working 1 Answer

Move Object A's Y position towards Object B's Y position 1 Answer

C# move y position of object not working 2 Answers

Keep a min distance away from object while moving towards it 0 Answers


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