RigidBody moving my cube, improper coordinates

I have a cube placed at 0,1,0, and once the program is started after testing I found that rigidbody’s gravity is causing my cube ti continuously moving around coordinates when it actually isnt moving in the program. I could be clicking absolutely nothing and it will say its moving ±5 units. Its on a completely flat surface. I have beyond confused. Screenshot by Lightshot

I can confirm that it starts at 0,0,0 heres the code:

using System.Collections;
using UnityEngine;

public class TumblingCubes : MonoBehaviour
{

public float tumblingDuration = 0.2f;

void Update()
{
var dir = Vector3.zero;

if (Input.GetKey(KeyCode.UpArrow))
dir = Vector3.forward;

if (Input.GetKey(KeyCode.DownArrow))
dir = Vector3.back;

if (Input.GetKey(KeyCode.LeftArrow))
dir = Vector3.left;

if (Input.GetKey(KeyCode.RightArrow))
dir = Vector3.right;

if (dir != Vector3.zero && !isTumbling)
{
StartCoroutine(Tumble(dir));
}
var vec = transform.eulerAngles;

transform.eulerAngles = vec;

}

bool isTumbling = false;
IEnumerator Tumble(Vector3 direction)
{
var vec = transform.eulerAngles;

transform.eulerAngles = vec;
isTumbling = true;

var rotAxis = Vector3.Cross(Vector3.up, direction);
var pivot = (transform.position + Vector3.down * 0.5f) + direction * 0.5f;

var startRotation = transform.rotation;
var endRotation = Quaternion.AngleAxis(90, rotAxis) * startRotation;

var startPosition = transform.position;
var endPosition = transform.position + direction;

var rotSpeed = 90 / tumblingDuration;
var t = 0.0f;

while (t < tumblingDuration)
{
t += Time.deltaTime;
transform.RotateAround(pivot, rotAxis, rotSpeed * Time.deltaTime);
yield return null;
}

transform.rotation = endRotation;
transform.position = endPosition;

isTumbling = false;

}

}

this is the only script attachted to the cube, other than rigidbody

** after disabling the script this is thee outcome,??? weird coordinates Screenshot by Lightshot

Drag the left border of the Inspector window to the left to expand its width. You’ll see that the position values are like:

2.192971e-08

This is the scientific notation in the form of E-notation. The above number can be written as:

2.192971*(10 ^ -08)

Which equals to:

0.00000002192971

So what you’re seeing are very small numbers in the boundary of the physics precision. In practice, it’s safe to assume that the value is 0.

1 Like