public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
}
// Use this for initialization
// We marked this as “Fixed” update because we
// are using it to mess with physics
void FixedUpdate;()
{ // Add a forward force
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);
// Only executed if condition is met
if (Input.GetKey("d"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
if (Input.GetKey("a"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
}
Problem was that you closed your script at line 7,
public class playermovement : MonoBehaviour {
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
} // <== the engine wont read anything after this line
It should be like this :
public class playermovement : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 2000f;
public float sidewaysForce = 500f;
void FixedUpdate()
{
rb.AddForce(0, 0, ForwardForce * Time.deltaTime);
// Only executed if condition is met
if (Input.GetKey("d"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0);
}
if (Input.GetKey("a"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0);
}
}
}
Note that fixed update is usefull with physic calculation, but its not interesting to put input function in