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 superbsumit · Jul 18, 2013 at 03:01 PM · c#cameraitween

Camera animation using EasyTouch's swipe and iTween

Hi all,

I am using EasyTouch for swiping and I wanted to have a swipe animation for my camera using iTween.

In simple words, I wanted is a perfect swipe for my game, in which my camera will move a little close to target transform when swipe is small or move farther when swipe is big. The target here will be the fixed transform position, from where the camera transform could not go beyond.

Currently I am doing this :

 public Transform targetRightCam;
 
 public Transform targetLeftCam;
 
 public float transSpeed;
 
 private void On_Swipe(Gesture gesture)
      {
         if(gesture.touchCount == 1)
         {
             if (gesture.swipe == EasyTouch.SwipeType.Right)
             {
                 target = targetLeftCam;
                 iTween.RotateTo(gameObject, iTween.Hash("rotation", target.eulerAngles, "time", transSpeed));
                 iTween.MoveTo(gameObject, iTween.Hash("position", target.position, "time", transSpeed));
             }
 
             else if(gesture.swipe == EasyTouch.SwipeType.Left)
             {
                 target = targetRightCam;
                 iTween.RotateTo(gameObject, iTween.Hash("rotation", target.eulerAngles, "time", transSpeed));
                 iTween.MoveTo(gameObject, iTween.Hash("position", target.position, "time", transSpeed));
             }
         }
     }

It works, but not the way I wanted as it is not based on swipe distance, it just moves the camera to the target position in a one single swipe event(whether small or big). So please if anyone has some suggestions or answers, please help. Also I am newbie to iTween library.

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

Answer by DannyB · Jul 18, 2013 at 03:26 PM

A few suggestions:

As for the touch library:
I am not familiar with EasyTouch, but I could not find anything in its sparse documentation that tells me if its swipe detection provides the caller with information about the swipe (e.g. distance). If it does, you need to use it. If it does not, you need to look for another method in its documentation that provides that, or switch to another gesture detection library (Input.Touches is one that I can vouch for).

In some libraries, a Drag gesture may be closer to what you need, as it both provides continuous events as well as start point and end point of the gesture.

As for the tweening
Although I am a big fan of iTween I found out that it is better to avoid it in some situations. Some points for consideration:

  1. If you may want to interrupt the tween (e.g. user swipes left then immediately right) - avoid iTween.

  2. If the tweening is simple enough (and therefore can be replaced with SmoothDamp or something similar) - avoid iTween.

  3. If it is mission critical (e.g. happens a lot, or its timing is critical) - avoid iTween.

Some pseudo logic
In your case, I feel like you simply need to find the right tools for the job, but the logic should be the same:

 OnSwipe( SwipeInfo swipe ) {
 
     if( swipe.direction == Right ) {
         if( swipe.distance < myThreshold ) {
             ...
         }
         else {
             ...
         }
     }
     if( swipe.direction == Left ) {
         if( swipe.distance < myThreshold ) {
             ...
         }
         else {
             ...
         }
     }
 }

I know this is not a concrete answer, but I hope it helps in some way to put you on teh right track.


To answer your additional question, this is how an iTween call may look like if you want to use the target's position and speed:

 GameObject target;

 iTween.MoveTo( gameObject, iTween.Hash(
     "position", target.transform.position,
     "speed"   , target.speed
 ));

This of course assumes that target has a publicly accessible speed variable.

Comment
Add comment · Show 5 · 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 superbsumit · Jul 19, 2013 at 06:09 AM 0
Share

thanks for the cool suggestions, ok so could you help me with iTween more. Is there any function in iTween which could move my gameObject to target( by passing target's position and the moving speed of target, as a parameter of HashTable)..?

avatar image DannyB · Jul 19, 2013 at 07:55 AM 0
Share

It looks like you are already doing it in the code in your question. You are only using "time" ins$$anonymous$$d of "speed" (which is fine if that is what you want).

In any case, added some more stuff to the answer.

avatar image superbsumit · Jul 19, 2013 at 08:59 AM 0
Share

ok yeah, sorry for that, I started using iTween from yesterday only, I've not seen that :p

avatar image superbsumit · Jul 19, 2013 at 11:55 AM 0
Share

Hi @DannyB, I m here again..:( and basically here is the thing : I have a room, and I want the user to move inside the room by swiping on his phone screen. There will be some fixed target positions(lets say 3 now) in which the user can move. So on first swipe, the user moves to its fixed target position, and on swiping again, he moves to the next fixed target position, and so on.. so could you provide me some sort of script, which does somewhat similar animation to what I want to achieve, with my camera animations.

avatar image DannyB · Jul 19, 2013 at 12:04 PM 0
Share

Well, this discussion is quickly moving away from the original question and is more suitable for the forums than the Answers. If you have a particular coding problem, Answers is suitable, otherwise, the forums.

But as a quick tip, I can tell you that two approaches come to $$anonymous$$d:

  1. Have a GameObject nextTarget in your script, and change it to point to the next target. This variable can either change by an inside trigger, or any outside source.

  2. Have a generic list or queue or array (as suitable) of game objects, which will hold all the targets, and something (again internal or external) will change its index.

In both cases, the iTween simply takes this current target as its destination.

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

16 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

Related Questions

Distribute terrain in zones 3 Answers

Switching Between (many) different iTween Paths (C#) 0 Answers

Itween path, how to find the closest point to the player/Vector3 2 Answers

Multiple Cars not working 1 Answer

Change the background color attribute of a camera in C#? 2 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