Rigidbody.position: How can i make my player to not leave the field
Hi guys! I'm new using unity for a couple of days, and i can't make my player to not leave the playfield on a tutorial "Space shooter - Moving the player"(https://www.youtube.com/watch?v=rVSLczG1M1E&list=PLX2vGYjWbI0RibPF7vixmr4x8ONJX-mNd∈dex=6). When i debug my code, the error that comes is
Error CS1061: 'UnityEngine.Component' does not contain a definition for 'position' and no extension method 'position' accepting a first argument of type 'UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp)
Here is my code: using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour
{
[System.Serializable]
public class Boundary {
public float xMin, xMax, zMin, zMax;
}
private Rigidbody rb;
public float speed;
public Boundary boundary;
void Start()
{
GetComponent<Rigidbody>().position = Vector3.zero;
}
void FixedUpdate ()
{
float speed = 10;
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
rb = GetComponent<Rigidbody> ();
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb = GetComponent<Rigidbody> ();
rb.velocity = new Vector3 (moveHorizontal * speed, 0.0F, moveVertical * speed);
Vector3.zero = new Vector3 (
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
0.0f,
Mathf.Clamp (rigidbody.position.z, boundary.zMin, boundary.zMax)
);
}
}
Any help? Ps: Sorry for my english, like my unity skills, i'm working on it, so if you see my english bugs, tell me.