Project space shooter problem

I was watching the projects of unity and i decided to make project space shooter. my space ship, background, lights were ready. Then I make the script to move the space ship as was told in the video. after it was completed, i decided to test it. my space ship was moving but when i moved it, it return to his original position and cannot move my space ship after a certain distance. Help me with this please !!! The script was this :-

using UnityEngine;

using System.Collections;

[System.Serializable]

public class Boundary {

public float xMin, xMax, zMin, zMax;

}

public class PlayerController : MonoBehaviour {

public float speed;
public float tilt;
public Boundary boundary;

void FixedUpdate ()
{
	float moveHorizontal = Input.GetAxis ("Horizontal");
	float moveVertical = Input.GetAxis ("Vertical");
	
	Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
	GetComponent<Rigidbody>().velocity = movement * speed;
	
	GetComponent<Rigidbody>().position = new Vector3 
		(
			Mathf.Clamp (GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax), 
			0.0f, 
			Mathf.Clamp (GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
			);
	
	GetComponent<Rigidbody>().rotation = Quaternion.Euler (0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);

I had the same problem! It is because you did not change the boundary values after you wrote them into your code.

if you want to use physics in the game, then you should probably AddForce to the rigidbody (Unity - Scripting API: Rigidbody.AddForce) instead of setting velocity and position of rigidbody

if you want to move the gameobjects yourself then you don’t need rigidbody at all and you should affect Transform.position of the gameobject

Yes the boundary has to be reset in the scene view, or at least that’s what I did. Thank you for the answer!

private Rigidbody rb;

void Start () 
{
    rb = GetComponent <Rigidbody> ();
}

Include it, so you dont have to put GetComponent (); every time you want to call the rigidbody.
just need to put this (Ex: rb.position)