• 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 /
This question was closed Jul 17, 2012 at 03:15 AM by Eric5h5 for the following reason:

Duplicate Question

avatar image
Question by Mz3D · Jul 17, 2012 at 12:59 AM · positionrandomspacemathfpingpong

Mathf.PingPong from a random position problems

How can i make multiple objects - at a random position in the space - to start moving from where they are to point B (4,0,0) and then back to a point A ( - 4,0,0) using Mathf.PingPong without strange effects?

Let's start. To make an object move from ( - 4,0,0) and not from (0,0,0) to a desired point on the x axis (in t$$anonymous$$s case 4,0,0) the Mathf.PingPong has to be corrected a little, like t$$anonymous$$s:

 transform.position = Vector3(Mathf.PingPong(Time.time, 8) - 4, 0, 0);

But t$$anonymous$$s way the various objects in my scene jump all togheter to a single point in space, intersecting with eachother, and then they start moving between -4 and 4. The only way to make the objects start moving from where they are, following separate paths, seems to be adding their transform.position value to the code, like t$$anonymous$$s:

 transform.position = transform.position + Vector3(Mathf.PingPong(Time.time, 8) - 4, 0, 0);

But t$$anonymous$$s results in making the objects start travelling really fast along the positive x axis, reac$$anonymous$$ng very $$anonymous$$gh values and disappearing from the game view. To correct t$$anonymous$$s i added a Vector3.Scale using very low values to compensate, like t$$anonymous$$s:

 transform.position = transform.position + Vector3.Scale(Vector3(Mathf.PingPong(Time.time, 8) - 4, 0, 0)), Vector3(0.008, 1, 1));

But even t$$anonymous$$s has a terrible effect! it merges objects speed and objects movement range in only one value (you can't control them separately anymore. If you modify 0.008 or 8 or any other value it result in changing both the t$$anonymous$$ngs). What can i do to make these objects starting their "ping pong movement" along the x axis from their random position in the space, without undesired effects like jumping all together to a single point or start travelling towards very $$anonymous$$gh x values? Please help me!

It's not a time related problem: i already tried to create a time variable and set it to 0 at the moment the PingPong movement starts but the results are the same.

Comment

People who like this

0 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 Eric5h5 · Jul 17, 2012 at 03:14 AM 0
Share

I already answered this here: http://answers.unity3d.com/questions/283498/relative-and-absolute-values-problem.html

0 Replies

  • Sort: 

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

mathf.pingpong 0 Answers

Ping pong position using lerp 3 Answers

Random position without overlap. HELP! 1 Answer

How can I calculate and place a GameObject at a random place just outside the camera frustrum? 0 Answers

spawn game object in random position 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