- Home /
Why wont my camera controller work,Why isnt my script working for a camera controller?
so i created a mouselook camera and im getting two errors for two lines of code and i cant figure out what the problem is, can any one help?
     smoothV.x = Mathf.Lerp(smoothV.x, md.x, if / smoothing);
     smoothV.y = Mathf.Lerp(smoothV.y, md.x, if / smoothing);
using System.Collections; using System.Collections.Generic; using UnityEngine; public class camMouseLook : MonoBehaviour { Vector2 mouseLook; Vector2 smoothV; public float sensitivity = 5.0f; public float smoothing = 2.0f;
 GameObject character;
 void Start()
 {
     character = this.transform.parent.gameObject;
 }
 void Update()
 {
     var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
     md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
     smoothV.x = Mathf.Lerp(smoothV.x, md.x, if / smoothing);
     smoothV.y = Mathf.Lerp(smoothV.y, md.x, if / smoothing);
     mouseLook += smoothV;
     transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
     character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
 }
} ,so i created this script for the mouse to move the camera in a first person game, but I get an error message for two lines of coding. smoothV.x = Mathf.Lerp(smoothV.x, md.x, if / smoothing); smoothV.y = Mathf.Lerp(smoothV.y, md.x, if / smoothing); can any one figure out the problem?
using System.Collections; using System.Collections.Generic; using UnityEngine; public class camMouseLook : MonoBehaviour { Vector2 mouseLook; Vector2 smoothV; public float sensitivity = 5.0f; public float smoothing = 2.0f;
 GameObject character;
 void Start()
 {
     character = this.transform.parent.gameObject;
 }
 void Update()
 {
     var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
     md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
     smoothV.x = Mathf.Lerp(smoothV.x, md.x, if / smoothing);
     smoothV.y = Mathf.Lerp(smoothV.y, md.x, if / smoothing);
     mouseLook += smoothV;
     transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
     character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
 }
}
Can you tell us what the errors are? whats unity saying?
Answer by A5B · Jan 21, 2019 at 12:20 AM
Are you getting a compiler error? Your code looks like it's trying to divide a variable named "if" by a variable named "smoothing":
 smoothV.x = Mathf.Lerp(smoothV.x, md.x, if / smoothing);
However, "if" is a reserved keyword (for the if block) and so cannot be used as a variable name. Try renaming "if" to something else. For example:
 smoothV.y = Mathf.Lerp(smoothV.y, md.x, some_other_name / smoothing);
Your answer
 
 
             Follow this Question
Related Questions
Save Camera Rotation ERROR (HELP!!!!) 1 Answer
How do I disable mouse to turning right 0 Answers
Mouselook in space, without a 'down' or 'up' 1 Answer
Override MouseLook/FirstPersonController 0 Answers
Change Input In Game 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                