Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by pintee · Oct 02, 2012 at 12:48 AM · itweencurve

Make an object follow a curved path using iTween

Hi, I have asked a few questions now and have gotten responses for all so i am grateful and hope this trend continues. My current question is in regards itween. Say you have a cube at (0,0,0). How do you make it travel along a curved path? Bear in mind moveToBezier is deprecated in 2.0. A code snippet would be much appreciated. Thank you all in advance.

Comment
Add comment · Show 3
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 Shrandis · Oct 04, 2012 at 08:39 AM 0
Share

Hellooooo....? Are you still there? Only you can close the case!

avatar image pintee · Oct 04, 2012 at 09:56 AM 0
Share

Hi Shrandis, thanks for your answer. But if i was to be more detailed with my requirements then I would have to also add that i need the curved path to be a different random curved path each time(how would you come up with the waypoint coordinates??). Also the curve has to have easing, which i don't think putonpath allows. Do you know how to do this?? But nevertheless i think you answered my original question. Thanks again.

avatar image Shrandis · Oct 04, 2012 at 10:10 AM 0
Share

Hmm, I do not know if you can have that much control over the path with iTween. You may need to write a path system yourself.

Glad if I could help, don't forget to press the green tick & thumbs up buttons if the answer helps you.

2 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Shrandis · Oct 03, 2012 at 10:29 AM

You can use iTween's PutOnPath function.

Simple example:

Create "waypoint" gameobjects. (empty gameobjects). Then, assign those waypoints in the order you want to waypointArray.

     public Transform[] waypointArray;
     float percentsPerSecond = 0.02f; // %2 of the path moved per second
     float currentPathPercent = 0.0f; //min 0, max 1
         
     void Update () 
     {
         currentPathPercent += percentsPerSecond * Time.deltaTime;
         iTween.PutOnPath(gameObject, waypointArray, currentPathPercent);
     }
     
     void OnDrawGizmos()
     {
         //Visual. Not used in movement
         iTween.DrawPath(waypointArray);
     }

Keep in mind that PutOnPath may have some issues if your goal is to make a movement with constant speed. (I'm not going into detail because it isn't what OP asked)

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 Alter · Feb 25, 2013 at 12:43 AM 0
Share

This is actually perfect for what I was looking for myself, however how would I go about making the gameobject turn/face the way it's moving also to add a jump feature?

I have this setup if it helps;

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$ovement : $$anonymous$$onoBehaviour {
  
     private float smoothing = 1.0f;
     private Vector3 targetPosition;
     
     public float runSpeed = 0;
     private int jumpCount = 0;
     public float jumpForce = 1.0f;
     
     public float gravity = 10;
     
     public Transform[] path;
     
     float percentsPerSecond = 0.02f; // %2 of the path moved per second
     float currentPathPercent = 0.0f; //$$anonymous$$ 0, max 1
 
  
     // Use this for initialization
     void Start () {
         
         Physics.gravity = new Vector3(0, -gravity, 0);
  
     }

     // Update is called once per frame
     void Update () 
     {
         
         bool grounded;
         
         
         currentPathPercent += percentsPerSecond * Time.deltaTime;
            iTween.PutOnPath(gameObject, path, currentPathPercent);
         
         
         //JU$$anonymous$$P//
         if (Physics.Raycast (transform.position, -transform.up, 1)) 
        {
          grounded = true;        
          //reset our jump count since we hit the ground //0 for double jump
          jumpCount = 1;   
                 
        } 
  
        else 
        {
          grounded = false;
          float amtTo$$anonymous$$ove = Input.GetAxisRaw ("Horizontal") * 0.1f * Time.deltaTime;     
        }
  
  
        if (Input.Get$$anonymous$$eyDown ("space") && (grounded || jumpCount < 1)) 
        {
          rigidbody.AddRelativeForce (transform.up * jumpForce, Force$$anonymous$$ode.Impulse);
        }
 
     }
     
     void OnDrawGizmos(){
         iTween.DrawPath(path);
     }
 }



avatar image aceleeon5 · Jun 26, 2014 at 01:52 AM 0
Share

Sounds like you got pretty far with it! how did this turn out?

avatar image
1

Answer by Koyemsi · Sep 12, 2019 at 11:08 AM

Replying to an old thread, but some may find this useful...

One can also use iTween.MoveTo() with a "path" attribute. The path has to be an array of Transform or Vector3.

Here is an example :

 public GameObject movingObject;
 public Transform[] waypoints;
 float speed = 2f;
 
  iTween.MoveTo(movingObject, iTween.Hash(
             "path", waypoints,
             "time", speed,
             "easetype", iTween.EaseType.easeInOutQuad));
 
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

12 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

Related Questions

Can iTween be used to constrain motion for an arbitrarily drawn curve? 1 Answer

iTween for Dynamically Moving Objects around a Sphere 0 Answers

Itween for curved orbital movement? 1 Answer

Navigate Curve at Constant Speed 3 Answers

iTween Put On Path percentage 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