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 jeango · Jun 12, 2014 at 09:19 AM · itweensine-wave

Using iTween for a sine-wave motion

Hi all, I'm new to iTween but I would really like to create a sine motion for an object.

It's for a shoot'em'up game, and I want my projectiles to move up and down on the y axis and to keep moving forward along the x axis.

I don't want to use paths, because they are restricted to 10 nodes and as far as I can tell, there is no way to move an object relative to a path (they always start at the position of the start node of the path, which is not what I want). So I'm trying to set up tweens.

I've tried to add two "MoveBy" tweens, one with a pingpong loop along the y axis, and one with no loop along the x axis. However it seems you can't combine tweens of the same type.

Is there a way to achieve this in iTween at all, or do I have to code all this manually?

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

Answer by robertbu · Jun 12, 2014 at 08:19 PM

I don't want to use paths, because they are restricted to 10 nodes and as far as I can tell

This is not true. As far as I know, the only limitation on paths length is available memory.

But if you did not want to use a path, then write a simple script that moves your object up and down in a sine motion using local coordiantes. Then make your visible object a child of an empty game object. The empty game object is what you use with iTween.

Here is a simple script that moves an object up and down on the its local position in a sine movement:

 #pragma strict
     var max = 2.0;
     var speed = 2.0;
  
 function Update () {
     var f = Mathf.Sin(Time.time * speed) * max;
     transform.localPosition = Vector3(0.0, f, 0.0);
 }
Comment
Add comment · Show 3 · 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 jeango · Jun 13, 2014 at 10:38 AM 0
Share

I guess you can programmatically set as many nodes as you can for a path, but in the visual editor, the "Node Count" slider is restricted to 10 as a maximum.

Thanks for that workaround, I didn't think of using two separate objects, pretty clever :-)

$$anonymous$$eanwhile I had come up with my own solution:

 public class SineWave$$anonymous$$oveScript : $$anonymous$$onoBehaviour {
 
     public float speed = 10.0f;
     public float amplitude = 1.0f;
     public float frequency = 0.0f;
 
     private float previousOffset = 0.0f;
     private float refAngle = 0.0f;
     void Start() {
     }
     // Update is called once per frame
     void Update () {
         // The base idea: use a reference angle that is increased according to frequency, and use its sine value to calculate the motion on the y axis.
 
         // we update the reference angle according to deltaTime and the frequency
         refAngle += 360*Time.deltaTime*frequency;
         // we make sure the angle is never > 360
         refAngle = $$anonymous$$athf.Repeat(refAngle, 360);
 
         // we calculate the new offset of the gameobject on the y axis
         float yOffset = ($$anonymous$$athf.Sin(refAngle*$$anonymous$$athf.Deg2Rad) * amplitude);
 
         // we move the gameObject on the axis 
         transform.Translate(Vector3.up*(yOffset-previousOffset));
         previousOffset = yOffset;
 
 
         // we use the "right" axis to move the gameobject on the x axis
         transform.Translate (Vector3.right*speed*Time.deltaTime);
 
     }
 
 }
avatar image robertbu · Jun 13, 2014 at 02:32 PM 0
Share

I haven't played with the node editor in forever, but did you try and increase the node count in the Inspector? $$anonymous$$y guess is that it defaults to 10 nodes, but you can reset the value to any value in the Inspector.

avatar image jeango · Jun 13, 2014 at 05:29 PM 0
Share

I tried to manually set the node count to 12 in the inspector, but it got reset to 10 as soon as I hit enter.

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

21 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

Related Questions

iTween sine wave like movement 1 Answer

Stop iTween destroying all tweens 0 Answers

Itwen MoveTo - jump 1 Answer

What is the difference of iTween and Waypoint? 0 Answers

iTween.RotateAdd Gives Wrong Results 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