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
1
Question by trelobyte · Jul 23, 2013 at 09:13 PM · cameralerprect

Camera.rect lerp not working

hi I trying to animate the camera normalised viewport rectangle on the click of a button but it moves without regarding the lerp function i have put in there here is the code:

 using UnityEngine;
 using System.Collections;
 
 public class moveCam : MonoBehaviour {
     public float open;
     public float closed;
 
 
     void OnClick ()
     {    
         Camera.main.rect = new Rect (0, 0, Mathf.Lerp (open, closed, Time.time), 1f);
         
     }
 
 }

Any help is greatly appreciated thanks

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 Eric5h5 · Jul 23, 2013 at 09:15 PM 0
Share

http://answers.unity3d.com/questions/14288/can-someone-explain-how-using-timedeltatime-as-t-i.html

avatar image trelobyte · Jul 24, 2013 at 05:15 PM 0
Share

Thank you guys you are so good i cannot believe it !

avatar image clunk47 trelobyte · Jul 24, 2013 at 05:15 PM 0
Share

Please post comments as comments, not as new answers.

2 Replies

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

Answer by Seth-Bergman · Jul 23, 2013 at 09:39 PM

you are only calling this for one frame, so it will jump to the precise size determined by that exact Time.time..

first, have a look here:

http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Lerp.html

in the example, in the update function, we are returning a slightly different value each frame for "Time.time". since it is called every frame, the effect is animated over time.. There are plenty of ways to accomplish what you want..

here's one:

 float stepper = 0.0f;
 bool clicked = true;
 float speed = .01f;
 void Update ()
 {
 
 if(clicked && stepper < open){
 Camera.main.rect = new Rect (0, 0, Mathf.Lerp (open, closed, stepper), 1f);
 stepper+= speed;
 }
 else if(!clicked && stepper > closed){
 Camera.main.rect = new Rect (0, 0, Mathf.Lerp (closed, open, stepper), 1f);
 stepper-= speed;
 }

 if(Input.GetMouseButtonDown(0))
 clicked = !clicked;
 }

just an example

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 clunk47 · Jul 24, 2013 at 05:16 PM 1
Share

If this resolved your issue, accept and vote up the answer.

avatar image clunk47 · Jul 25, 2013 at 08:36 PM 0
Share

@trelobyte I voted up your question so you should have enough karma now to vote up this answer. It is always good to vote up the answer you accepted.

avatar image
0

Answer by jamesflowerdew · Mar 07, 2015 at 12:28 PM

This might be helpful :)

am just writing in the lerp not using mathf, but it works, and as a function .

 Rect LerpRect(Rect nRect1, Rect nRect2,float nNum){
         Rect vRect=nRect1;
         vRect.x+=(nRect2.x-nRect1.x)*nNum;
         vRect.y+=(nRect2.y-nRect1.y)*nNum;
         vRect.width+=(nRect2.width-nRect1.width)*nNum;
         vRect.height+=(nRect2.height-nRect1.height)*nNum;
         return(vRect);
     }
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

19 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

Related Questions

Zoom camera to correct FoV based on Rect size 1 Answer

How to move camera from point A to B 1 Answer

How to make camera position relative to a specific target. 1 Answer

Camera Lerp Jitter 0 Answers

3D menu camera rotation issue. 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