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 JokerMartini · Jul 19, 2012 at 07:37 PM · transformobjectmove

move object on x position to new specific x position

My goal here is to move and object from it's starting position on creation, to a targeted x position which is chosen at random from an array which contains a mix of locations.

I have a variable which contains a collection of random points in 3d space.

variable of random locations: var pointsCol = [0,5,10],[10,15,30],[5,3,0]

objects starting location: startPos = [0,0,0]

objects targeted end location: endPos = [10,15,30]

find the difference in the two "X" positions: stepX = (startPos.x - endPos.x)

divide the difference in positions by "10": stepX = (startPos.x - endPos.x) / 10

result: 1

My syntax is not right by any means but i was hoping I could get some help on this. I'm doing it in javascript. I appreciate the help. Thanks

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TehWut · Jul 19, 2012 at 10:16 PM

alright, I'm no coder, but this might work.

 vecArray:Vector3[]

this will create an array of vector3 positions to store. set the length in the inspector (three in your case).

Then you could do this in code, or through the inspector.

 vecArray[0] = Vector3(5,5,5);  // or whatever your positions are

once you have all 3 vectors, you could pick a position like this.

 transform.position = vecArray[Random.Range(0,vecArray.length)];

what this does is pick a random vector3 from the array using random.range.

Now you can apply the rest of your functions for calculating positions and other things.hope this helps! If you need further assitance, I'd be happy to help.

EDIT: whoops, looks like I misunderstood your question entirely! I'll work this out and get back to you!

 vecArray:Vector3[];
 vecArray[0] = transform.position;
 vecArray[1] = vecArray[Random.Range(0,vecArray.length)]; // picks a random goal position

 var goalPos:Vector3 = ((vecArray[1] - vecArray[0]) / 10)  // you may have to reverse the vectors, or use Mathf.Abs for absolute values

    transform.position.x = goalPosition.x;

Something like this?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Opening a door at proximity 2 Answers

How do you make an object go left and right? 1 Answer

using Transform on a Object will not move it 100% exactly... 1 Answer

Move a object and then return , like loop 2 Answers

Make Object Move to another Object 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