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 Jan 03, 2015 at 07:31 PM by Inan-Evin for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Inan-Evin · Jan 03, 2015 at 07:07 PM · lerpmathfarcpingsin

Arc Movement Lerp, Mathf.Sin and Mathf.Pingpong question

Hello everyone, i am trying to move an object from a point to b, and b to a, in short using Mathf.PingPong. But on the way, i want it to make arc movement, like it's bending. So I have searched a bit and figured out how to make the PingPong lerping, and also how to make the Arc movement. But I couldn't mix them together, because I couldn't create logic between timings. Let me clarify the movement I want once more, and then you can look at the script below. I want the object to move from a to b, and have an arc movement with Mathf.Sin, but it should go up only one time in each travel.

 float t = Mathf.PingPong(Time.time * speed, 1.0f); // ping pong the lerping
 
 currentPos = Vector3.Lerp(startPos, endPos, t);
 
 currentPos.y += bending.y * Mathf.Clamp01(Mathf.Sin(Time.time * 2f)); // clamp the mathf.sin in order to have the bending only in positive way. 
 
 go.position = currentPos;

When I change the "2f" value in Mathf.Sin, i am able to adjust the speed of the sin wave, but obviously if i change the speed of ping pong, this changed 2f value will no longer work. I need a value dependent on the time of travel, to multiply with Time.time in Mathf.Sin. But couldn't create the equation.Can someone help ? Thanks :).

Comment
Add comment · Show 2
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 Inan-Evin · Jan 03, 2015 at 07:30 PM 0
Share

Dude you just made me realize the thing, i was so foolish. Thanks dude !

avatar image Scribe · Jan 03, 2015 at 07:31 PM 0
Share

No problem :)

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Scribe · Jan 03, 2015 at 07:25 PM

 t = Mathf.PingPong(Time.time * speed, 1f);
 pos.y = Mathf.Sin(t*Mathf.PI);
 pos.x = Mathf.Lerp(start.x, end.x, t);

The angle given to sin is expected at a radian, and so Sin(0) = 0, Sin(PI/2) = 1, Sin(PI) = 0, hence you want to times your t value (which moves from 0 to 1) by PI so that it changes between 0 and PI!

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

Follow this Question

Answers Answers and Comments

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

Related Questions

Move object in an arc 3 Answers

Mathf.Lerp not working 2 Answers

How Make a Simple Altimeter? 1 Answer

How to update interval between objects in run time? 0 Answers

Move and Rotate player in circular motion? 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