Here's the thing. I am making a 3D top-down game about cars on the road. Right now I have different-colored cuboids representing cars. They are position-locked in Y and rotation-locked on all three axis (axises? Sorry, English isn't my first language). The cuboid in question is controlled with the following code:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
public float speed;
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)
);
}
}
It's pretty simple, almost unchanged code from the Unity tutorial. Boundaries are set as -8, 8 on X and -13, 13 on Z. The cuboid spawns at 0, 0.55 (It's 1 height, I gave it some clearance), -13. I move it forward with the WASD and it just gets stuck at 0.15 Z. Just dies there and can't move anywhere.
I'm very new to Unity, so I expect it to be some rookie mistake. Can someone help me out? Thank you.