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'
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
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.
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.
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
Your answer
![](https://koobas.hobune.stream/wayback/20220612051603im_/https://answers.unity.com/themes/thub/images/avi.jpg)