Problem with the Unity camera

3

I'm creating a game with unity 5 in 2d, and tried to create a script for the camera to follow the character by moving the camera transform. For this I followed some tutorials on youtube but when I was compiling the code indicated in the Lerp method, I tried to adjust the code in several ways and I did not get a solution, which I send here and the last version of the code that I have changed infinitely many times.

    
asked by anonymous 08.02.2016 / 17:29

2 answers

3

As the error message indicates, your call to the Lerp method expects parameters other than those you passed on. It expects two Vector3 ( a and b ) and float ( t ), because what this method does is interpolate between two vectors a and b in a t .

You are passing in the first parameter, for example, MCamera.position.x , which is the x component (a float value) of the position vector. You should probably pass MCamera.position directly (and the same goes for the parameter transform.position.x , which should be only transform.position ).

If your interest is to interpolate only the value of x itself, experiment with Vector3(transform.position.x, 0, 0) (create a new vector with only its value x , and with the 0 value for the components y and z ).

  

Q.: You should also make the last line be MCamera.position = vetor instead of MCamera.position.x = vetor .

    
10.02.2016 / 18:26
0

An alternative would simply be to drag the House to in (child) of the Character. Thus, whenever the character moves, the camera goes behind without needing to write a single line of code.

    
25.02.2016 / 15:09