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 srsobieraj · Feb 20, 2012 at 03:24 AM · cameralerplocal

How Can I Linear Interpolate (Lerp) in Local Space?

I'm trying to smooth the motion of my camera by using Lerp (I had previously been using Transform.translate). This has worked for panning my camera left and right, but I have my camera pitched downward at 45 degrees and I would like my scroll wheel to move the camera in Local Z (ie, along the camera view path).

Lerp cannot take Space.Self as an argument, so how can I achieve this?

(If possible a C# solution would be appreciated, but I can translate a JS answer to C#)

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 yusufulutas · Feb 20, 2012 at 08:35 AM 0
Share

You can use "$$anonymous$$athf.Smoothdamp".

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by srsobieraj · Feb 21, 2012 at 01:14 AM

Solved.

You can get the local vector by using transform.InverseTransformDirection().

 Vector3 relativeMoveVector = transform.InverseTransformDirection(moveVector);
 myCamera.position = Vector3.Lerp(myCamera.position, myCamera.position + relativeMoveVector, Time.deltaTime * smoothingFactor);
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
avatar image
0

Answer by Berenger · Feb 20, 2012 at 04:01 AM

Keep in mind that lerp is a really straight forward function. It's "how much i do take from a, and how much do I take from b". Thus, the space you're working on is irrelevant. What you mean is a lerp between a position and that position minus a certain distance along it's forward vector (here is the space.self). It's up to you to find that a and that b. Then the wheel will control the t in Lerp(a, b, t).

Comment
Add comment · Show 4 · 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 srsobieraj · Feb 20, 2012 at 05:35 AM 0
Share

It's up to you to find that a and that b.

I understand that. I'm having a hell of a time getting my value for 'b' though. $$anonymous$$y 'a' value is just the .position of my camera, and t is negotiable depending on how much I want to smooth everything.

However, 'b' is escaping me. Here's my snippet:

     Vector3 moveVector = Vector3.forward * Input.GetAxis("$$anonymous$$ouse ScrollWheel") * zoomSpeed * Time.deltaTime;
     
     if (IsInBounds(moveVector))
     {
         myCamera.position = Vector3.Lerp(myCamera.position, myCamera.position + moveVector, Time.deltaTime * smoothingFactor);
     }    
avatar image Berenger · Feb 20, 2012 at 05:58 AM 0
Share

The way you're calculating mouseVector, you don't need Lerp : just Tranlaste in world space or transform.position += mouseVector. However, you wont have any boundaries, which mean you can step back infinitely or go further than your target. It's not a bad solution, just be aware of it. If you're having a free camera, it's actually not a problem.

avatar image srsobieraj · Feb 20, 2012 at 06:04 AM 0
Share

How would I calculate moveVector in a way that I can have boundaries?

I'd like my camera to have smoothed motion and be bounded.

Thanks in advance, I realise I'm asking a lot of questions.

avatar image Berenger · Feb 20, 2012 at 07:00 AM 0
Share

I had in $$anonymous$$d a camera focus on a target, then I would have a startPos near the target, an endPos away from the target, then moved the camera like that transform.position = Vector3.Lerp( startPos, endPos, wheel ) with wheel the mouseWheel between 0 and 1.

But if you have a pan and maybe a lookaround, that's more complicated. you'll have to know if your inside the sphere / box that represent your world I guess.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

[QuaternionSlerp] Lookback script 1 Answer

Easy transition between multiple views? 1 Answer

Single Camera Lerping between three characters? (code provided) 0 Answers

Lerp and recording Transforms/Vector3 1 Answer

How you change another script value smoothly on trigger 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