• 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 PvTGreg · May 21, 2015 at 09:33 PM · pingpong

smoother pingpong?

Hi im trying to recreate rusts walking animation with guns using code so that i can have a universal walking animation im trying to use pingpong for this but it seems way to jumpy it reaches the point and jumps a little is there a way to stop this?

 timer -= Time.deltaTime;
         transform.localPosition = Vector3.Lerp (animationSettings.walkRightPos, animationSettings.walkLeftPos, Mathf.PingPong (timer * animationSettings.animSpeed  , 1.0f));
Comment
Add comment · Show 17
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 Vice_Versa · May 21, 2015 at 09:39 PM 0
Share

ins$$anonymous$$d of 1.0f at the end did you try using a smaller value?

avatar image PvTGreg · May 21, 2015 at 09:53 PM 0
Share

i have yes and the result was that the movement didnt happen at all and a larger value made it insane fast

avatar image PvTGreg · May 21, 2015 at 09:55 PM 0
Share

i have also tried using time.time and using them both directly which did not smooth things

avatar image Vice_Versa · May 22, 2015 at 12:02 AM 0
Share

when you say "jumpy" what exactly do you mean?

avatar image save · May 22, 2015 at 10:06 PM 1
Share

If you're looking for easing in and out you could try approaching it like this as well:

 timer -= Time.deltaTime;
         transform.localPosition = Vector3.Lerp (animationSettings.walkRightPos, animationSettings.walkLeftPos, .5f+($$anonymous$$athf.Sin(timer * animationSettings.animSpeed)/2f));

The solution is within what the t parameter of Vector3.Lerp looks like, where in your script it has a linear stepping based on the frame rate and nothing that tells it to ease in and out. I'm not sure though if easing is the opposite of "jumpy" as described. :)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by 0V3RR1D3 · May 22, 2015 at 10:40 PM

Set 1.0f to 10*Time.deltaTime

This will constantly smooth it out, Try it.

The higher 10 is the fast it will move.

Comment
Add comment · Show 2 · 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 Bunny83 · May 23, 2015 at 12:44 AM 1
Share

Sorry but this makes no sense. Do you understand what PingPong does and why there's a 1.0? Using "10*dt" at a frame rate of about 60fps means you pingpong between 0 and 10/60 (== 1/6 ~~ 0.166). So you never lerp to the end but only 1/6 of the actual distance.

Besides that changing the pingpong range will result in a "jumpy" behaviour since pingpong "wraps" the value around at the given range.

avatar image 0V3RR1D3 · May 23, 2015 at 03:47 AM 1
Share

Then use ($$anonymous$$athF.sin(ang*$$anonymous$$athF.DegToRad) + 1) * distance

and then in an update loop do

ang += 1*Time.deltaTime

That would pingpong between -1 and 1, So by doing + 1 its between 1 and 2, Devide it by 2 to get 0-1 and then times it by the distance, Do the same for x,y and z. Sorry if it makes no sence I am really bad at wording things but this would work and would not be choppy

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.

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

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

Mathf.PingPong from a random position problems 0 Answers

Can I use two objects in my project with Mathf.PingPong script attached to both 1 Answer

Moving two game objects in To and Fro motion continuously? 2 Answers

mathf.pingpong with offset 1 Answer

Play animation forward than immediately backwards, once (ie single pingpong) 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