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 Rick74 · Nov 24, 2013 at 09:58 PM · javascriptmathfsmoothdamp

MathF.SmoothDamp

Hey, I'm trying to simply translate the camera from one position to the next. I'm getting the error;

Assets/Scripts/InGameGUI.js(471,46): BCE0023: No appropriate version of 'UnityEngine.Mathf.SmoothDamp' for the argument list '(UnityEngine.Vector3, UnityEngine.Vector3, float)' was found.

However from my end, the code looks sound.

Anyone have any ideas of what I've missed?

 function CameraStart ()
 {
     var camStartPosition     = Vector3 (11.5, 0, -5);
     var camEndPosition         = Vector3 (0, 0, -5);
     
     transform.position         = camStartPosition;
     
     var getCamSpeed : int = 0;
     getCamSpeed = camSpeed;
     
     getClock.GetComponent(clock).playTimeEnabled = false;
 
     camSpeed = 1.0;
     
     yield WaitForSeconds (7);
     
     transform.position = Mathf.SmoothDamp(camStartPosition, camEndPosition, camSpeed * Time.deltaTime); 
     
     //moveCamCenter = true;
     yield WaitForSeconds (5.5);
     getClock.GetComponent(clock).playTimeEnabled = true;
     camSpeed = getCamSpeed;
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Nov 24, 2013 at 10:36 PM

It seems you mixed up Mathf.SmoothDamp with Vector3.SmoothDamp.

Mathf.SmoothDamp works only on single float values while Vector3.SmoothDamp works on vector3s.

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 Rick74 · Nov 24, 2013 at 11:07 PM 0
Share

hey thanks for the info Bunny!

Unfortunately, when I changed the line to;

transform.position = Vector3.SmoothDamp(camStartPosition, camEndPosition, camSpeed * Time.deltaTime);

I just recieved a different error;

Assets/Scripts/InGameGUI.js(471,48): BCE0023: No appropriate version of 'UnityEngine.Vector3.SmoothDamp' for the argument list '(UnityEngine.Vector3, UnityEngine.Vector3, float)' was found.

:(

avatar image Bunny83 · Nov 25, 2013 at 02:03 AM 0
Share

Well, SmoothDamp needs at least 4 parameters and yours are actually quite wrong.

  • The first parameter is your current position so you have to pass transform.position

  • The second parameter is the target you want to reach. This should probably be your camEndPosition

  • For the third parameter you have to pass a velocity vector which is modified by the function. It uses this variable to store the current velocity. You just have to pass a Vector3 variable

  • The forth parameter is the smooth time. You shouldn't multiply this value by Time.deltaTime. It's the approximate time in seconds.

  • The last two parameter doesn't have to be specified. maxSpeed could be used to avoid a velocity greater than this value. By default it's infinity, so if necessary the function could crank up the velocity up to "ludicrous speed". Finally there's deltaTime which by default is, well, Time.deltaTime ;)

So far about what you have to pass to the function. The next thing is the function has to be called each frame to work properly. It seems you call it just once.

Another thing is you have an int variable getCamSpeed but assign a float value to it. $$anonymous$$eep in $$anonymous$$d that you will loose the fraction when you do this.

There's way to much wrong in your code and it's hard to say what's the actual behaviour you're after.

It's quite late here (03:00), so i'm off ;)
Good luck

avatar image Rick74 · Nov 25, 2013 at 12:21 PM 0
Share

Thanks for checking back with me Bunny. I checked up on the API regarding Vector3.SmoothDamp. And made some alterations to the code as you suggested.

 private var camStart:            boolean = true;
 
 function Update
 {
       if (camStart)
            {
            CameraStart ();
            camStart = false;
            }    
 }
 function CameraStart ()
 {
     var camStartPosition     = Vector3 (11.5, 0, -5);
     var camEndPosition         = Vector3 (0, 0, -5);
     var velocity             = Vector3 (-5, 0, 0);
     
     transform.position         = camStartPosition;
     
     var getCamSpeed : int = 0;
     getCamSpeed = camSpeed;
     
     getClock.GetComponent(clock).playTimeEnabled = false;
 
     camSpeed = 5.5;
     
     yield WaitForSeconds (7);
     
     transform.position = Vector3.SmoothDamp(camStartPosition, camEndPosition, velocity, camSpeed ); 
     
     //moveCamCenter = true;
     yield WaitForSeconds (5.5);
     getClock.GetComponent(clock).playTimeEnabled = true;
     camSpeed = getCamSpeed;
     
 }
 
 

However the end result was the camera either stopped moving after 1 frame, or jittered....depending if I had the camStart boolean at the end of the function itself, or after the CameraStart call in function Update (). (I'm unsure why I would get different results depending , as it should equal the same thing in either place?)

The goal of this code was to simply have the camera start on camStartPosition, hold for several seconds, then pan smoothly over to the camEndPosition.

I was currently using Vector3.Lerp to move the camera from one position to the next, but I dislike the slow into the camEndPosition that seems to be the trademark of using a Lerp.

I will try to dig into this code and see if there isn't anything else fighting with it.

Thanks.

avatar image Ryan-Gatts · Apr 15, 2014 at 05:58 AM 1
Share

I don't know if you're still fiddling with this, but you are missing a time argument in your smoothDamp and you aren't feeding in the current position. You currently have:

Vector3.SmoothDamp(camStartPosition, camEndPosition, velocity, camSpeed );

The way you've written this asks the camera to move to a specific point in between camStartPosition and camEndPosition, rather than move between them. What you want is:

Vector3.SmoothDamp(transform.position, camEndPosition, velocity, Time.deltaTime * camSpeed );

Think of it this way: Vector3.SmoothDamp( whereAmI, whereAmIHeaded, how$$anonymous$$uchWasI$$anonymous$$ovingLastFrame, how$$anonymous$$uchShouldITryTo$$anonymous$$oveThisFrame * timeSinceLastFrame );

If you want to delay the start of the move, animate the value for camSpeed. If camSpeed = zero, the camera won't move at all. Then just ease into whatever speed you want.

avatar image
0

Answer by leventalpsal · Oct 16, 2015 at 10:02 AM

Hi, @Ryan got point, you are giving the start position, you should give the current position (which is the same as start position only at the start ) and apply that return value to current position.

You must also give the velocity parameter as reference so that the function can modify it and use the new velocity value next time.

And the 4th param should represent time as float. Something that won't change.

Also execution order is not correct I think.

So it should be something like this : (c#)

void camStart() { float smoothTime = 5.5f; Vector3 camStartPosition = new Vector3 (11.5, 0, -5); var camEndPosition = new Vector3 (0, 0, -5); var velocity = new Vector3 (-5, 0, 0); transform.position = camStartPosition;

void update() { if(cameraStarted) { transform.position = Vector3.SmoothDamp(transform.position, camEndPosition, ref velocity, smoothTime ); } }

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 Bunny83 · Oct 16, 2015 at 11:11 AM 0
Share

Didn't I mention that in my comment that is 2 years old? Ryan just repeated some of my points but got the Time.deltaTime wrong again. His post is actually one year old....

avatar image leventalpsal Bunny83 · Oct 16, 2015 at 11:40 AM 0
Share

@Bunny83 I've mentioned multiple points which one are you saying? Yes you have mentioned to call the function in every frame, but there is the "reference" detail that hasn't been mentioned before by anyone.

This won't work:

transform.position = Vector3.SmoothDamp(transform.position, camEndPosition, velocity, smoothTime );

This will:

transform.position = Vector3.SmoothDamp(transform.position, camEndPosition, ref velocity, smoothTime ); // ref velocity

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

Time goes wrong in the Build 1 Answer

Mathf.SmoothDamp happens instantly 1 Answer

My rotation affects a value it should not. 0 Answers

SmoothDamp from 360 to 1 1 Answer

Mathf.Smoothdamp, need help troubleshooting! 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