[Solved] Mesh shakes after moving 1000 units

Project files are in the second post.

YouTube video link of the problem:http://www.youtube.com/watch?v=Ak3Zj8TsVb4

I’m having a problem where my mesh object starts to shake more and more the further it gets from (Unity Inspector Transform Positions) 0.0.0 starting after about 1000,-1000 on any axis…

Here’s my setup.

Setup 1.
Uses rigidbody forces to move forward and rotate.
Uses drag and angularDrag.

Mesh <— control script, rigidbody :
|___Main Camera

Setup 2.
Uses only transforms to move forward and rotate. No rigidbodys.

Mesh <— control script
|___Main Camera

Setup 3.
Uses only transforms to move forward and rotate. No rigidbodys.

Main Camera <— control script
|___Mesh

Setup 4. ---- Works Fine
Uses only transforms to move forward and rotate. No rigidbodys.

Main Camera <— control script

Setup 5. ---- Works Fine
Uses rigidbody forces to move forward and rotate.
Uses drag and angularDrag.

Main Camera <— control script, rigidbody :

Setups 1,2,3 start to shake after moving 1000 units. The Main Camera stays still it’s only the mesh that shakes.

Setups 4,5 Removing the mesh from the setup and only having the Main Camera with the control script everything works fine.

Project files removed…

I don’t need to look at your project, as this is a common problem. It’s down to floating point inaccuracy. The larger your numbers get, the less number of decimal places can be maintained with accuracy, and the shaking results from this relative lack of accuracy.

You can try adjusting your scales to see if you can minimize this problem but the usual solution is to not move things too far away from the World origin. This is often accomplished by keeping the “player” at the origin and moving everything else around it. This essentially means that all the shaking things are a long way from the player and therefore the shaking is not visible.

Of course, this is likely to be much more difficult with rigid body physics involved. Maybe adjusting your scales might be enough to solve it, and you won’t have to worry about complex solutions.

Ok. So in order to maintain the preconceived scale i should just scale things down?

I’ll work with this and see what happens. Thanks for the information.

What about using fixed-point integers?

My first idea was: use GUITexture instead of mesh, but then I noticed that you have lighting on your mesh, so yeah that wouldn’t work.
Another solution is to have the mesh in camera space and then just render it like that without transforming it into worldspace. Unfortunately you can’t just do that, because Unity transforms everything into worldspace for you, but there is a workaround. You could create another camera and keep it at 0, 0, 0 and just control the orientation and render only you 1st-person spaceship into it. That way you would avoid precision problems and get directional lighting on it.

BTW: I’m surprised that you’re having problems with precision at 1000units level. (from my personal experience) I wouldn’t expect them to start earlier than 10000 unless you have something very weird in your proportions. Maybe your 1st person ship is very small?

I just started work so I’ll look into this more once I get home , but The ship is just under one unity unit in size, and is currently the smallest player craft I have planed.

If i’m reading you correctly i could have a setup something like this:

Main Camera —> locked at 0,0,0 + control scripts
| |
| |----<-----<-----<— |
|…^
|…|
|_Player Camera —> Player View
|
|_Mesh

If thats correct. How can i transfer the view of the Player camera attached to the mesh; to the Main camera?

Ok i’m trying to create the method as mentioned above. I’ve created a fixed camera at 0,0,0 and attached a “remote control” script to it so i can control the ship with out being attached to it.

Here is the remote control script for anyone who would like to use it.

Download at bottom of post…
//

var Throttle=0.0;
var Pitch =0.0;
var Yaw =0.0;
var Roll =0.0;

private var ShipClass : GameObject;

function Awake()
{
ShipClass = GameObject.Find(“/Fighter”);
}

function FixedUpdate ()
{

Throttle = Input.GetAxis(“Throttle”);
Pitch = Input.GetAxis(“Pitch”);
Yaw = Input.GetAxis(“Yaw”);
Roll = Input.GetAxis(“Roll”);

if (Throttle !=0){
ShipClass.rigidbody.AddRelativeForce (0,0,-100Throttle);
}
if(Pitch != 0) {
ShipClass.transform.Rotate (-1
Pitch,0,0,Space.Self);
}
if(Yaw != 0) {
ShipClass.transform.Rotate (0,1Yaw,0,Space.Self);
}
if(Roll != 0) {
ShipClass.transform.Rotate (0,0,-1
Roll,Space.Self);
}

}

//

Where i’m getting lost at is the part of having the fixed camera render the player ship camera. Is there some documentation on doing this?

Or am i going about it wrong?

I know you can override some rigidbodies physics properties in script by.

function Awake()
gravity = 0;
rigidbody.mass = somenumber;
rigidbody.drag = somenumber;

so the rigidbody.drag and .mass are script over rides. Is there a physics.origin over ride?

aka.

function FixedUpdate()
physics.origin = transform.Translate(player)

I came across this on youtube. The uploader was having the same problem but has fixed it.

“FP-precision fix is implemented by translating every physics object in the scene such that the player becomes the origin (0,0,0)”

This sounds similar to what Paulius was mentioning, but different.

Is there some documentation on doing this?

Ok i think i’m starting to understand.

I was on the right track with my Remote Control script. Instead of it controlling the ship i needed it to control the world. So this is my setup now.

Hierarchy:

Main Camera <— Player
|
|___Ship Mesh

World <— Environment the player interacts with.
|
|__All assets that make up the world.

So as the player inputs controls for flight instead of the player moving inside the “World”, it’s the “World” and all of it’s assets that move.

Now i have the rotation setup correctly but i can’t get the player to move in the direction that currently being faced. I can only get it to move on the world Z axis.

I know it’s because i dont have it properly linked but i’m just not sure how to tell the world to move based on the players direction.

var Throttle=0.0;
var Pitch =0.0;
var Yaw =0.0;
var Roll =0.0;

private var ShipClass : GameObject;

function Awake()
{

ShipClass = GameObject.Find(“/World”);
}

function FixedUpdate ()
{

Throttle = Input.GetAxis(“Throttle”);
Pitch = Input.GetAxis(“Pitch”);
Yaw = Input.GetAxis(“Yaw”);
Roll = Input.GetAxis(“Roll”);

if (Throttle !=0){
ShipClass.rigidbody.AddRelativeForce (0,0,-100Throttle);
}
if(Pitch != 0) {
rigidbody.AddRelativeTorque (-1
Pitch,0,0);
}
if(Yaw != 0) {
rigidbody.AddRelativeTorque (0,1Yaw,0);
}
if(Roll != 0) {
rigidbody.AddRelativeTorque (0,0,-1
Roll);
}

}