Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Hey Guys got stuck with errors CS0103, CS1503, CS1502:

$
0
0
The errors for CS0103: The name forwardInput does not exist in the current context CS1503 : Argument #1 cannot convert object expression to type float CS1502: The best overloaded method match for UnityEngine.Mathf.Abs(float) has some invalid arguments The coding in questions are: CS0103: rBody.velocity = transform.forward * forwardInput * forwardVel; CS1503: if (Mathf.Abs(forwardInput) > inputDelay) CS1502: if (Mathf.Abs(forwardInput) > inputDelay) My code is: using UnityEngine; using System.Collections; public class Controller : MonoBehaviour { public float inputDelay = 0.1f; public float forwardVel = 12; public float rotateVel = 100; Quaternion targetRotation; Rigidbody rBody; float fowardInput, turnInput; public Quaternion TargetRotation { get { return targetRotation; } } // Use this for initialization void Start () { targetRotation = transform.rotation; if (GetComponent()) rBody = GetComponent(); else Debug.LogError("The Character Needs A Rigidbody."); forwardInput = turnInput = 0; } void GetInput() { forwardInput = Input.GetAxis("Vertical"); turnInput = Input.GetAxis("Horizontal"); } // Update is called once per frame void Update () { GetInput(); Turn(); } void FixedUpdate() { Run(); } void Run() { if (Mathf.Abs(forwardInput) > inputDelay) { //move rBody.velocity = transform.forward * forwardInput * forwardVel; } //zero velocity rBody.velocity = Vector3.zero; } void Turn() { targetRotation = Quaternion.AngleAxis(rotateVel * turnInput * Time.deltaTime, Vector3.up); transform.rotation = targetRotation; } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles