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.
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.
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.
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”);
}
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;