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 /
  • Help Room /
avatar image
0
Question by vespa39 · Dec 06, 2015 at 05:48 PM · error messageclonemario

i am having issues with my mario clone project

here is my Mario Clone script that i am doing for my class: if someone can help me with this i would really appreciate it thanks in advance. i have redone this many times - thinking i am missing something from my teachers video - but i keep getting the same error,, any reasons why this would happen?

public class Camerafollow : MonoBehaviour {

 public Transform target;
 public Transform leftBounds;
 public Transform rightBounds;

 public float smoothDampTime = 0.15f;
 private Vector3 smoothDampVelocity = Vector3.zero;

 private float camWidth, camHeight, levelMinX, levelMaxX;

 // Use this for initialization
 void Start () {

     camHeight = Camera.main.orthographicSize * 2;
     camWidth = camHeight * Camera.main.aspect;

     float leftBoundsWidth = leftBounds.GetComponentInChildren<SpriteRenderer>().bounds.size.x / 2;
     float rightBoundsWidth = rightBounds.GetComponentInChildren<SpriteRenderer>().bounds.size.x / 2;

     levelMinX = leftBounds.position.x + leftBoundsWidth + (camWidth/2);
     levelMaxX = rightBounds.position.x - rightBoundsWidth - (camWidth/2);
 
 }
 
 // Update is called once per frame
 void Update () {

     if (target) {

         float targetX = Mathf.Max(levelMinX, Mathf.Min(levelMaxX, target.position.x));

         float x = Mathf.SmoothDamp(transform.position.x, targetX, ref smoothDampVelocity, smoothDampTime);

         transform.position = new Vector3(x, transform.position.y, transform.position.z);

     }
 }

}

and here is the error messages i am getting

Assets/scripts/Camerafollow.cs(36,29): error CS1502: The best overloaded method match for UnityEngine.Mathf.SmoothDamp(float, float, ref float, float)' has some invalid arguments Assets/scripts/Camerafollow.cs(36,29): error CS1503: Argument #3' cannot convert UnityEngine.Vector3' expression to type float'

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
0
Best Answer

Answer by bubzy · Dec 06, 2015 at 06:26 PM

your error is on this line

 float x = Mathf.SmoothDamp(transform.position.x, targetX, ref smoothDampVelocity, smoothDampTime);

Which is effectively

    float x = Mathf.SmoothDamp(
 Argument #1 transform.position.x, 
 Argument #2 targetX, 
 Argument #3 ref smoothDampVelocity, //This is not a float value as the error indicates, it is a Vector3, you will need to change this to a float or use one of the values. x,y,or z from the Vector3
 Argument #4 smoothDampTime);

http://docs.unity3d.com/ScriptReference/Mathf.SmoothDamp.html these are the overloads for this function if you are considering using different methods/values

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 vespa39 · Dec 06, 2015 at 07:44 PM

thanks for replying, @ bubzy

when i changed this variable, private float smoothDampVelocity = Vector3.zero; the other error code i had before disappears and then i get this message can not convert a vector3 to a float - so i change it to private Vector3 smoothDampVelocity = Vector3.zero; and the error i had before shows up - I am not quite understanding how to write or change the code.

Comment
Add comment · Show 3 · 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 bubzy · Dec 06, 2015 at 11:46 PM 0
Share

a Vector3 is made of 3 floating point values like this

Vector3 test = new Vector 3(floatA, floatB, floatC);

as a result, the compiler is trying to make a single float value out of those 3 values. which it cannot do.

you can use:

private float smoothDampVelocity = 0; //as you are using Vector3.Zero

you can also change the value 0 to be whatever you wish it to be.

avatar image vespa39 · Dec 07, 2015 at 12:50 AM 0
Share

thank you so much for replaying again, I think i understand now - i have been struggling with this error for a couple a weeks racking my brain- you rock :) thanks again and Happy Holidays

avatar image bubzy vespa39 · Dec 07, 2015 at 02:00 AM 0
Share

you're welcome, have fun :)

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

34 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

Related Questions

Errors after cloning the project [question updated] 0 Answers

Android Cardboard SDK published to WebGL - now using 5.4.1f1 0 Answers

All compiler errors have to be fixed, but I copy pasted the code from the tutorial roll a ball to ensure its right. It still gives me the error! 0 Answers

How do I fix this WaterBase error? 8 Answers

is my enemy selector null reference a problem? 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