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 superluigi · Jan 02, 2014 at 11:35 PM · javascriptmathfpingpong

Help with Mathf.PingPong

2 questions. 1) Why doesn't deltaTime work correctly and 2) what do I need to do to get my object to move from where it currently is in the world. With this code it jumps to zero and moves to 5, then returns to zero, back to 5, etc.

 transform.position.z = Mathf.PingPong(Time.time * 2, 5);
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 _-_ · Jan 02, 2014 at 11:58 PM

It's not exactly clear what you're trying to do, could you be a bit more specific (Like, how/where exactly do you want your object to move in relation to time)? Also, I'm not getting where you use deltaTime at all.

I'm assuming that your object is now moving between 0 and 5 and you want it to move between the object position and 5 or something?

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 superluigi · Jan 03, 2014 at 12:14 AM 0
Share

I just want it to move back and forth between 2 spots. It's doing that now but I have my object at 0,0,60 and this sends it all the way to 0,0,0 and makes it move between 0 and 5 on the z axis. I want to know what I can do to make it stay at 60 and move around that location.

avatar image
0

Answer by HappyMoo · Jan 02, 2014 at 11:58 PM

deltaTime doesn't work, because functions don't remember prior calls... you just insert something in and get the same output back every time you insert the same input.

so lets say your frametime is stable and you insert 0.0166 into this function, why do you expect a different output every time?

ping pong works like this:

 input, output:
 0, 0
 1, 1
 2, 2
 3, 3
 4, 4
 5, 5
 6, 4
 7, 3 
 8, 2
 9, 1
 10, 0
 11, 1
 12, 2
 13, 3

lets say you want to move from where you are now to pos = (10,5,2)

 Vector3 target = new Vector(10,5,2);
 float speed = 0.03f; // 0 - 1
 
 void Update()
 {
   transform.position = Vector3.Lerp(transform.position, target, speed);
 }

this means it it move 3%(speed=0.03) of the remaining path in every frame, which means it moves faster first and gets slower, because 3% of a path that is getting shorter and shorter is also a shorter distance every time.

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

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Does Mathf.PingPong always have to start at (0,0,0)? 1 Answer

Vector3.lerp and Mathf.pingpong not moving smoothly 3 Answers

MathF clamp not working 1 Answer

Ping pong position using lerp 3 Answers

Mathf function on GetKey 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