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 ikkman · Mar 08, 2015 at 01:33 AM · movement script

How to make gameObject (moving in sin wave) reach target position?

Hi,

Right now my gameObject is moving in sin wave through the following formula:

basePosition += transform.forward speed Time.deltaTime; transform.position = basePosition + transform.up amplitude Mathf.Sin(omega * Time.time);

I do have a target transform reference as well so if we suppose the previous gameObject reached this target, the state of the gameObject itself will change as the follow:

if (transform.position == target.position) state = State.End;

However, I don't have any control over the gameObject position when it reach the target position since it moves in sin wave. It may pass the target position from above or down and sometimes it may reach it with slight chance.

I tried dividing amplitude/omega by the distance between gameObject and the target but it did not work. Trying even distribution to ensure this forward movement based on sin wave will end by the end to the specified target position exactly.

Any idea?

regards, K

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 meat5000 ♦ · Mar 06, 2015 at 08:04 PM 0
Share

increase oscillation frequency to increase chance of hitting the point. Or, apply damping the closer you get to reduce the amplitude of the swing, helping you to not miss your point.

avatar image Glurth · Mar 08, 2015 at 01:52 AM 0
Share

Could you consider it "reached" the target it it get's within a distance that is less that 1/2 it's wave amplitude?

Or, are you trying to ensure it crosses a specific point? If this is the case; perhaps rather than base your sin wave on TI$$anonymous$$E, you can base it on the distance from target point. This way, when it reaches the destination, you'll know, sin(0)=0

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jpthek9 · Mar 08, 2015 at 01:50 AM

Just like you do it on a graph, 'cept you plug in time as X and output Y to height (or whatever axis you want to oscillate on.

transform.position.y = new Vector3(transform.position.x, Mathf.Sin(Time.time), transform.position.z);

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Moving AI away or towards player not working correctly. 1 Answer

Audio PlayOneShot Help 1 Answer

I can't get framerate independence to work... 1 Answer

Touch movement too slow 0 Answers

How to move 2D enemy AI's along the x-Axis? 0 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