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
3
Question by superluigi · Jan 04, 2014 at 01:01 AM · mathfpingpong

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

pretty much what the title asks. I copied the exaple right from the scripting reference but I noticed that u can't choose where it starts and where it ends like Lerp for example. All you can do is choose the time and the length.

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
15
Best Answer

Answer by Bunny83 · Jan 04, 2014 at 01:53 AM

Yes, like you can read in the docs it always ping-pongs between 0 and length. However if you want a different range, just add an offset. You can also create a helper like this:

 // C#
 float PingPong(float aValue, float aMin, float aMax)
 {
     return Mathf.PingPong(aValue, aMax-aMin) + aMin;
 }

 // UnityScript
 function PingPong(aValue : float, aMin : float, aMax : float) : float
 {
     return Mathf.PingPong(aValue, aMax-aMin) + aMin;
 }


Comment
Add comment · Show 8 · 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 04, 2014 at 04:58 AM 0
Share

thanks a lot. I'm gonna test it in a bit. It's a little confusing but I'll figure out which part does what when I test it.

avatar image Bunny83 · Jan 04, 2014 at 12:26 PM 0
Share

ps: If you want a correct "mapping", you would have to subtract a$$anonymous$$in from aValue when feeding it to $$anonymous$$athf.PingPong. However usually pingpong is only used with a constantly incrementing / decrementing value so it usually doesn't matter since it just "shifts" the ping-pong pattern start by a$$anonymous$$in.

That would make more sense when using $$anonymous$$athf.Repeat to clamp a value between a $$anonymous$$ and max value.

avatar image superluigi · Jan 04, 2014 at 10:54 PM 1
Share

I can't get it to work. Here's my code.

 var aValue : float = 10.0;
 var a$$anonymous$$in : float = 3.0;
 var a$$anonymous$$ax : float = 7.0;
 
 function Update ()
 {
     
 }
 function PingPong(aValue : float, a$$anonymous$$in : float, a$$anonymous$$ax : float) : float
 {
     return $$anonymous$$athf.PingPong(aValue, a$$anonymous$$ax-a$$anonymous$$in) + a$$anonymous$$in;
 }
avatar image superluigi · Jan 04, 2014 at 11:07 PM 2
Share

goth it to work. function PingPong is confusing as hell. But I added an offset like you said and it works like I want it to. I had already tried this but I didn't know how to get it to work. Anyway here's my working code.

 function Update () 
 {
     transform.position.z = $$anonymous$$athf.PingPong(Time.time, 15) + 5;
 }
avatar image Bunny83 · Jan 05, 2014 at 01:08 AM 3
Share

I think you got the purpose of my helper function wrong ;) $$anonymous$$y function just wraps $$anonymous$$athf.PingPong, so ins$$anonymous$$d of $$anonymous$$athf.PingPong you can use my PingPong:

 function Update ()
 {
     // the value would ping pong between 5 and 20
     transform.position.z = PingPong(Time.time, 5, 20);
 }
 function PingPong(aValue : float, a$$anonymous$$in : float, a$$anonymous$$ax : float) : float
 {
     return $$anonymous$$athf.PingPong(aValue, a$$anonymous$$ax-a$$anonymous$$in) + a$$anonymous$$in;
 }
Show more comments

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

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

Related Questions

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

mathf.pingpong 0 Answers

Make my mathf to Wait? :) 2 Answers

using Mathf.PingPong 1 Answer

Mathf.PingPong make the leaf jittering when the speed is changed. 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