- Home /
The question is answered, right answer was accepted
Whats wrong with this code? im new
whats wrong with this code? im doing teh roll a ball game project
using UnityEngine; using System.Collections;
public class NewBehaviourScript : MonoBehaviour { void Update () { } void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertial = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce (Vector3);
}
heres teh compiler errors:
Assets/Scripts/NewBehaviourScript.cs(11,70): error CS0103: The name moveVertical' does not exist in the current context Assets/Scripts/NewBehaviourScript.cs(11,83): error CS1502: The best overloaded method match for UnityEngine.Vector3.Vector3(float, float, float)' has some invalid arguments
Assets/Scripts/NewBehaviourScript.cs(11,83): error CS1503: Argument #3' cannot convert object' expression to type float' Assets/Scripts/NewBehaviourScript.cs(13,37): error CS0119: Expression denotes a type', where a variable', value' or method group' was expected Assets/Scripts/NewBehaviourScript.cs(13,27): error CS1502: The best overloaded method match for UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)' has some invalid arguments
Assets/Scripts/NewBehaviourScript.cs(13,27): error CS1503: Argument #1' cannot convert object' expression to type `UnityEngine.Vector3'
you have made a typo on the initialization "float moveVertial = Input.GetAxis ("Vertical");" i think you meant moveVertical
Format your code properly. This makes it easier for us to help you. The error seems to be, as Exbow pointed out, that you misspelt moveVertical and so your parameters for your movement vector are off. The other error is that the parameter for AddForce should be movement, not Vector3. Vector3 is a type of variable, movement is an actual variable with a value to assign and handle.
Answer by calmcarrots · Aug 14, 2014 at 05:17 AM
rigidbody.AddForce (movement);
//Vector3 is a type so you can't add a force to a Vector3. This fixed version is above
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
help my code has error CS8205 :parsing error how can I fix? 2 Answers
Can anyone help me with a simple CSharp error 1 Answer
Error CS8025: Parsing error. HELP! 1 Answer
Help calling a code in C# script 1 Answer