Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Error: the namespace '<global namespace>' already contains a definition for 'PlayerMovement'

VukeVuke Member
edited October 2020 in Programming

using UnityEngine;

public class PlayerMovement : MonoBehaviour {

public Rigidbody rb;

public float forwardForce = 2000f;

public float sidewaysForce = 500f; 

void Update ()


// Add a forward force

rb.AddForce(0, 0, forwardForce * Time.deltaTime);

if (Input.GetKey("d"))


// Add a force to the right

rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);


if (Input.GetKey("a")) // If the player is pressing the "a" key


// Add a force to the left

rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);





  • That just means there is another script in your project under the same name. You can either find it and delete it or change the name of this script(both in the project tab in unity and in the script itself ).

Sign In or Register to comment.