• 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 Chris12345 · Jul 23, 2013 at 07:19 PM · itween path

Itween change paths smoothly?

hello, i have 3 paths how can i change paths smoothly and over time to the next path because right now it just appears on the next path?

 using UnityEngine;
 using System.Collections;
 
 public class follow : MonoBehaviour {
     public bool IsleftOn = false;
     public bool IsRightOn = false;
     private float smoothing = 100f;
     private Vector3 targetPosition;
 
     public float runSpeed = 0;
 
     public Transform[] path0;
     public Transform[] path1;
     public Transform[] path2;
 
     private Transform[][] paths = new Transform[3][];
     private int iPath = 1;
 
 
     float percentsPerSecond = 0.02f; // %2 of the path moved per second
     float currentPathPercent = 0.0f; //min 0, max 1
 
     void Start () {    
     paths[0] = path0;
     paths[1] = path1;
     paths[2] = path2;
     }
 
     void Update () {  
           IsleftOn = PlayMakerGlobals.Instance.Variables.GetFsmBool("leftcontrol").Value;
           IsRightOn = PlayMakerGlobals.Instance.Variables.GetFsmBool("rightcontrol").Value;
           runSpeed = PlayMakerGlobals.Instance.Variables.GetFsmFloat("playerspeed").Value;
            if  (IsleftOn == true) {
                 if (iPath == 2) iPath = 1; else iPath = 0;
                 PlayMakerGlobals.Instance.Variables.GetFsmBool("leftcontrol").Value = false;
 
            }
 
            else if (IsRightOn == true) {
                 if (iPath == 0) iPath = 1; else iPath = 2;
                 PlayMakerGlobals.Instance.Variables.GetFsmBool("rightcontrol").Value = false;
            }
        currentPathPercent += percentsPerSecond * runSpeed;
        iTween.PutOnPath(gameObject, paths[iPath], currentPathPercent);
        transform.LookAt(iTween.PointOnPath(paths[iPath],currentPathPercent+.01f));
     }
 
     void OnDrawGizmos(){
        iTween.DrawPath(path0);
        iTween.DrawPath(path1);
        iTween.DrawPath(path2);
     }
 }
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
1
Best Answer

Answer by robertbu · Jul 23, 2013 at 09:54 PM

Do you really need three paths? If all the paths are parallel, could you send an empty game object down the center path with the physical game object as a child? Moving to the right or left path would be Lerping the local coordinate left or right with respect to the parent.

If you want/need to stick to three paths, I would also use a local offset. That is I'd move to the new path but then set the local position so that object was in the previous position. Then Lerp() the postion to Vector3.zero; To make this work, you will have to catch lane change events.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

15 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

Related Questions

A node in a childnode? 1 Answer

Walk cycle not importing smoothly. 0 Answers

how to move multiple object towards the center(0,0,0) ? 1 Answer

iAd Keeps Sending 0 Answers

[A bit offtopic] Simulated eye sight 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges