Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 mike29willems · Mar 05, 2019 at 12:06 AM · lerpsmoothfollow

Vector3.Lerp is not reacting, pls help (simple script)

public Transform target; public float speed; public Vector3 offset;

 private void FixedUpdate()
 {
     Vector3 DesiredPosition = target.position + offset;
     transform.position = DesiredPosition;
     Vector3 Smoothing = Vector3.Lerp(transform.position, DesiredPosition, speed);
     transform.position = Smoothing;

}

Changing the smoothing(speed) doesn't effect the smoothing(speed) let a lone getting a smoothing. I made a simple cube with a movement script and a camera with a camera script^^. Only when I would change the cube script to update and camerascript to fixed update I would get some smoothing but then again changing the smoothing(value) didn't affect it and it glitched. I have a MacBook Pro and iam running the latest version of Unity. The weird thing is that I literally copied the scripts from Youtube_Unity and Youtube_Brackeys but they didn't work I tried a lot am I missing something? (By the way there was even a point where my camera flew the opposite way in a straight line of what it should follow... )

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 RobAnthem · Mar 05, 2019 at 12:20 AM 0
Share

Lerp doesn't work how you think it does. The 3rd parameter of lerp is not a "speed" parameter, its the distance from point A to point B in percentage. So if you were to lerp between A and B at .5f then you would end up always being at the center between both objects. Lerp is simply a linear interpolation between 2 points. What you want is like transform.position = Vector3.$$anonymous$$oveTowards(transform.position, desiredPosition, speed * Time.fixedDeltaTime);

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by WarmedxMints · Mar 05, 2019 at 12:29 AM

You have a few mistakes there Firstly,


  1. unless your transform has a rigidbody attached, you should really be updating its position in Update as FixedUpdate is for physics instructions.

  2. You are setting the transform's position to your desired position before you even start the lerp.

  3. It looks like you are confused over the 3rd parameter for the lerp method.


The 3rd parameter of the lerp method which Unity calls time could also be called percent. It is not how long the lerp will take, it is a percentage from the startpoint to the endpoint. The method uses a range of 0 - 1 for this. So 0 would return the start point (1st parameter) and 1 would return the endpoint (2nd parameter). The method also clamps the time parameter to 1 so even if you put 1000 in there, it would still return the endpoint.


This code should do what you wish;

     private void Update()
     {
         var DesiredPosition = target.position + offset;
         transform.position = Vector3.Lerp(transform.position, DesiredPosition, Time.deltaTime * speed);        
     }



Although I would recommend using MoveTowards instead

     private void Update()
     {
         var DesiredPosition = target.position + offset;
         transform.position = Vector3.MoveTowards(transform.position, DesiredPosition, Time.deltaTime * speed);        
     }


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 mike29willems · Mar 05, 2019 at 11:59 AM

Thank you for ur reply, but it didn't worked... I copied ur script (and MoveTowards) but the camera just followed the target without smoothing. Since I am working on a project this is really annoying. This script is from Unity, is this also rong? (target is moving in fixed update and has a Rigidbody). Lastly what value do I need to paste in smoothing to be sure it really should smooth? Do I need to make a quick video cus it is still not working so u can see everything.


public Transform target; public float smoothing = 5f; Vector3 offset;


Void Start () { offset = transform.position - target.position;}


Void FixedUpdate() { targetCamPos = transform.position + offset; transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing); }

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 mike29willems · Mar 05, 2019 at 12:21 PM 0
Share

btw this is the code where my camera flew away

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

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

Related Questions

Smooth animation scrubbing with the mouse 3 Answers

How can I get a game object to follow something smoothly without using lerp. 0 Answers

why target switching of smooth camera not very smooth ? 0 Answers

Vector3.Lerp and MoveTowards not smoothing (simple script) 2 Answers

Moving player in an arc, from startPoint to endPoint 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