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 Lumind · Jul 18, 2014 at 11:14 AM · c#positioncamera-movement

Smooth change of camera position goes wrong

have this code to smoothly change the camera position:

 public GameObject MyCam;
     public float strength;
 Vector3 cameraPosition = new Vector3(22.44445f, -3, 4.542897f);
         MyCam.transform.position = Vector3.Lerp(transform.position, cameraPosition, strength);

however it sends my camera to absolutely different position(for example, 3.008285,-9.02228,-12.27002) - I read that it depends some from the 3rd parameter (strength in my case, I tested it setting from 0,001 and up to 10 - and still not wanted result)

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
0

Answer by sethuraj · Jul 18, 2014 at 11:35 AM

Lerp is the short form of Linear Interpolation.Its used to linearly interpolate between two values,in this case two vector points.

Syntax of lerp for Vector3 is

Vector3.Lerp(Vector_One,Vector_Two,LerpValue)

The lerp value ranges from 0 to 1. No use in giving 10 or 100.

1) If lerp value is zero result is Vector_One.

2) If lerp value is one then result is Vector_Two.

3) If Lerp is 0.5f then result is in between Vector_One and Vector_Two

4) Lerp value should vary from 0 to one inorder to get the smooth transition

 public GameObject MyCam;
 public float strength=0.0f;
 
 Vector3 InitialPosition;
 Vector3 FinalPosition;
 
 void Start()
 {
   InitialPosition=transform.position;
   FinalPosition=new Vector3(22.44445f, -3, 4.542897f);
 }    
 
 void Update()
 {
   if(strength<1.0f)
   {
     strength+=Time.deltatime;
   }
 
   MyCam.transform.position=Vector3.Lerp(InitialPosition,FinalPosition,strength);
 }
Comment
Add comment · Show 1 · 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 Lumind · Jul 18, 2014 at 03:38 PM 0
Share

thanks for reply, it became smooth but I still don't understand why position of the camera in the end(when strength is 1 - 22.44445, -12.55874, 5.470654) is absolutely different from FinalPosition(22.44445f, -3, 4.542897f). The only axis that works correctly is X - it remains 22.44445f

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

C# Check If Scripted Gameobject goes Past Variable Gameobject 0 Answers

Rotate camera smoothly for particular position with single INPUT 0 Answers

How do I check if an Object isn't moving? (C#) 1 Answer

Positioning a GameObject so I't wont be inside another object 1 Answer

C# sticking to Cube corners position (raycasting AI script) 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