Can't get gravity to work proberly (transform)

So I’m using a transform as a player with a camera following it. Gravity works fine at start, also when I hit the floor mostly. Sometimes the transform starts to rotate in these weird directions and suddenly my player can fly around rotating forever in the void.
Here is a picture:
alt text

As you can see the cube had begun to rotate and floating.

It’s very random when it happens sometimes it works for just a while and then it screws up.

Here is my code:

var speed : float = 5.00;
var yVelocity : float = 10.00;
var gravity : float = 5.00;
var onFloor : boolean = false;

function Update () {
	plyMove();
	
	if(onFloor == false) {
		transform.position.y -= gravity * Time.deltaTime;
	} else {
		return;
	}
}

function plyMove () {
	if(Input.GetKey("s")) {
		transform.Translate(-Vector3.forward * speed * Time.deltaTime);
	}
	
	if(Input.GetKey("w")) {
		transform.Translate(Vector3.forward * speed * Time.deltaTime);
	}
	
	if(Input.GetKey("d")) {
		transform.Rotate(Vector3(0,15,0) * Time.deltaTime);
	}
	
	if(Input.GetKey("a")) {
		transform.Rotate(Vector3(0,-15,0) * Time.deltaTime);
	}
	
	if(Input.GetKeyDown("space")) {
		transform.position.y += yVelocity * Time.deltaTime;
	}
}

function OnCollisionEnter(theCollision : Collision) {
	if(theCollision.gameObject.tag == "floor") {
		onFloor = true;
	}
}

function OnCollisionExit(afterCollision : Collision) {
	if(onFloor == true) {
		onFloor = false;
	}
}

also I believe it could be something about the rotation, but im not sure.

Are you combining your own physics with some colliders? Maybe the built-in collisions in Unity are knocking your player around in weird directions when it hits the floor? Hitting the floor could cause your object to get some kind of momentum causing it to rotate forever or start moving on its own.

I’m not sure what you mean, as you can see in my code I’ve combined my own physics with colliders. Basicly this is all the code I have in my project, except the camera that follow the cube.

Here is the camera code if needed:
var target : Transform;
var smooth : float = 400;

function Update () {
	camMove();
}

function camMove () {
	transform.position.x = Mathf.Lerp(transform.position.x, target.position.x, Time.deltaTime * smooth);
}

EDIT:
I’ll just use rigidbody
Thanks for the answers