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

Duplicate Question

avatar image
0
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 this case 4,0,0) the Mathf.PingPong has to be corrected a little, like this:

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

But this 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 this:

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

But this results in making the objects start travelling really fast along the positive x axis, reaching very high values and disappearing from the game view. To correct this i added a Vector3.Scale using very low values to compensate, like this:

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

But even this 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 things). 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 high 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
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 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: 

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

Make an object move towards random spot on another objects edge? 1 Answer

instantiate random object in Specified positions? 1 Answer

Keeping the player inside the screen? 2 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