• 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
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

People who like this

0 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 TIME, 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

  • Sort: 
avatar image

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

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

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

Converting Input.getAxis("Horizontal") to touch screen input. 0 Answers

How can I enable my capsule to move; object 'target' not recognized. 0 Answers

How to stop player movement variable on collision (when button is still pressed down) 0 Answers

How do I fix this movement issue? 1 Answer

How to make the turn as we see in Runner games in UNITY? 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