using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 = new Vector3(moveHorizontal, 0.0f, moveVertical)
rigidbody.AddForce(Vector3);
}
}
Unity says that theres something wrong with the “regidbody” code that it was an error. i dont understand. Pls help me.
The problem is in the previous line. You are missing the ‘;’ at the end of the line. Note that if your mass is the default of ‘1.0’, then the amount of force you are adding is not very large. You may need something like:
rigidbody.AddForce(v3 * amount);
…where ‘amount’ is a variable set in the 5 to 50 range.
As robertbu pointed out, you’re missing a semicolon at the end of line 12. But based on the posted code you’re also not declaring a Vector3 variable that you assign your new Vector3 to. So, like this:
using UnityEditor;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 force = new Vector3(moveHorizontal, 0.0f, moveVertical);
rigidbody.AddForce(force);
}
}