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 Bentoon · Aug 24, 2014 at 10:07 PM · camera-movementitweenpatharrow-keys

put Camera on path with touch &/or arrow keys

Hello people Super grateful Robertbu helped me get my iTween Path working with Touch on my iOs devices, but now what if it I am on running on desktop...?

I want to use my arrow keys (either Up & Down or Left & Right) since it is on an iTween path and is simply bi - directional...

Here is the code I put on the Camera:

 using UnityEngine;
 using System.Collections;
  
 public class FlythroughCameraController1 : MonoBehaviour {
     public Transform[] movePath;
     public Transform[] lookPath;
     public Transform lookTarget;
     public float percentage;
     //public Transform[] path;
     public float speed = 0.1f;
  
  
     private float redPosition = .16f;
     private float bluePosition = .53f;
     private float greenPosition = 1;
 //  private float purplePosition = 1.2;
  
     //gui styling
     public Font font;
     private GUIStyle style = new GUIStyle();
  
     void Start(){
         style.font=font;
     }
  
     void Update () {
         if (Input.touchCount > 0) {
  
             Touch touch = Input.GetTouch(0);
  
             if (touch.phase == TouchPhase.Moved) {
                 percentage += touch.deltaPosition.x * speed / Screen.height;
                 percentage = Mathf.Clamp01(percentage);
                 iTween.PutOnPath(gameObject,movePath,percentage);
                 iTween.PutOnPath(lookTarget,lookPath,percentage);
                 transform.LookAt(iTween.PointOnPath(lookPath,percentage));
                 //transform.LookAt(iTween.PointOnPath(path,percentage+.05f));
             }
         }
     }
  
  
     void OnDrawGizmos(){
         iTween.DrawPath(movePath,Color.magenta);
         iTween.DrawPath(lookPath,Color.cyan);
         Gizmos.color=Color.black;
         Gizmos.DrawLine(transform.position,lookTarget.position);
     }
  
     void SlideTo(float position){
         iTween.Stop(gameObject);
         iTween.ValueTo(gameObject,iTween.Hash("from",percentage,"to",position,"time",2,"easetype",iTween.EaseType.easeInOutCubic,"onupdate","SlidePercentage"));    
     }
  
     void SlidePercentage(float p){
         percentage=p;
     }
 }
 


I'm a but lost with how the touch phase is using percentage & how I might create an "else if" Left or Right Arrow keys...?

     if(Input.GetKey(KeyCode.RightArrow))
     {
         something something
     }
     if(Input.GetKey(KeyCode.LeftArrow))
     {
         something something
     }

Thanks for taking time to look,

~ be

Comment
Add comment · Show 1
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 vuong_vin · Nov 22, 2014 at 03:29 AM 0
Share

Hello Bentoon, im looking for some way to make camera movement follow a path and seem your idea very interesting. Could you show all item to do camera follow a path in iOS device?

Thanks

1 Reply

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

Answer by robertbu · Aug 24, 2014 at 10:27 PM

 if(Input.GetKey(KeyCode.RightArrow))
 {
     percentage += speed * Time.deltaTime;
 }
 if(Input.GetKey(KeyCode.LeftArrow))
 {
    percentage -= speed * Time.deltaTime;
 }
 percentage = Mathf.Clamp01(percentage);

'speed' is a variable you define. Start by assigning it a value of 1.0f.

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 Bentoon · Aug 25, 2014 at 02:44 AM 0
Share

but It's in the Update function on Camera ?

     void Update () {
         if (Input.touchCount > 0) {
             
             Touch touch = Input.GetTouch(0);
             
             if (touch.phase == TouchPhase.$$anonymous$$oved) {
                 percentage += touch.deltaPosition.x * speed / Screen.height;
                 percentage = $$anonymous$$athf.Clamp01(percentage);

                 iTween.PutOnPath(gameObject,movePath,percentage);
                 iTween.PutOnPath(lookTarget,lookPath,percentage);
                 transform.LookAt(iTween.PointOnPath(lookPath,percentage));
             }
         }
 
 
         if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow))
         {
             percentage += speed * Time.deltaTime;
         }
         if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow))
         {
             percentage -= speed * Time.deltaTime;
         }
         percentage = $$anonymous$$athf.Clamp01(percentage);
     }



Thanks Rb,

avatar image robertbu · Aug 25, 2014 at 04:49 AM 0
Share

Yes, in Update(). Note you have what are really two different speeds here. One used for touch and one used for arrow keys. Rename and reassign one of them. The need to be separate values. For example in the new code fragment, rename 'speed' to 'arrowSpeed'.

avatar image Bentoon · Aug 25, 2014 at 04:53 AM 0
Share

Got it ! Thanks Rb, again, again

Here is the working code if others come apron this thread.

 void Update () {
         if (Input.touchCount > 0) {
             
             Touch touch = Input.GetTouch(0);
             
             if (touch.phase == TouchPhase.$$anonymous$$oved) {
                 percentage += touch.deltaPosition.x * speed / Screen.height;
                 percentage = $$anonymous$$athf.Clamp01(percentage);
                 // ROBERTBU                iTween.PutOnPath(gameObject,path,percentage);
                 iTween.PutOnPath(gameObject,movePath,percentage);
                 iTween.PutOnPath(lookTarget,lookPath,percentage);
                 transform.LookAt(iTween.PointOnPath(lookPath,percentage));
                 //transform.LookAt(iTween.PointOnPath(path,percentage+.05f));
             }
         }
 
 
         if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.RightArrow))
         {
             percentage += speed * Time.deltaTime;
         }
         if(Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftArrow))
         {
             percentage -= speed * Time.deltaTime;
         }
         percentage = $$anonymous$$athf.Clamp01(percentage);
         iTween.PutOnPath(gameObject,movePath,percentage);
         iTween.PutOnPath(lookTarget,lookPath,percentage);
         transform.LookAt(iTween.PointOnPath(lookPath,percentage));
     }
 

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

24 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 avatar image avatar image avatar image

Related Questions

Lerping between Camera Paths 1 Answer

[SCREENSHOTS] itween Path, orientToPath and gameObject rotation, 2D game 3 Answers

itween MoveTo IndexOutOfRangeException 0 Answers

How to create homing missile that follows path using Unity and iTween 1 Answer

How do Move a gameobject along a path WITHOUT A SPLINE 1 Answer


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