Abount quaternions and rotation
Posted: Tue Aug 19, 2014 10:53 am
Hi, I working with BEPU engine for a while and have some questions about it.
1. I am using BEPUPhysics for server-side physics engine, and in the other hand - Unity to draw everything on client side. So, from client come request to move player in some direction (in other words it send request with desired speed vector). I am using CharacterController and set it's Body Linear Velocity property to this vector. But I want to rotate a body to this direction as well. All rotation and orientation operations are using quaternions, but I didn't understand it well (honestly didn't understand at all). So here is my code :
So I getting actual forward direction. Multiplying speed vector from client with speed, then multiply Z part to -1 (I don't know why I need to do it, but for correct displaying in unity I need to do it). Then I took difference between actual and desired directions (orientations). And then add this difference to actual orientation. But on client it rotates character wrong. Maybe I doing something wrong? So :
2. I desided to do a simple app with BEPUPhysics (using XNAFramework). Add some entity's and try to rotate it in the same way. To see, maybe I am doing well, but problem in client side diasplaying. I created this app using some classes from demos, loaded static mesh, but didn't found any way to rotate it, so, how I can do it?
Thanks.
1. I am using BEPUPhysics for server-side physics engine, and in the other hand - Unity to draw everything on client side. So, from client come request to move player in some direction (in other words it send request with desired speed vector). I am using CharacterController and set it's Body Linear Velocity property to this vector. But I want to rotate a body to this direction as well. All rotation and orientation operations are using quaternions, but I didn't understand it well (honestly didn't understand at all). So here is my code :
Code: Select all
Vector3 frd = CharacterController.Body.OrientationMatrix.Forward;
Vector3 refVector = (WalkDirection * MoveSpeed);
refVector = new Vector3(refVector.X, refVector.Y, refVector.Z * -1);
Quaternion rot;
Quaternion.GetQuaternionBetweenNormalizedVectors(ref frd, ref refVector, out rot);
Quaternion Target = Quaternion.Concatenate(CharacterController.Body.Orientation, rot);
//CharacterController.Body.Orientation = Quaternion.Slerp(CharacterController.Body.Orientation, Target, 5.0f);
CharacterController.Body.Orientation = Target;
2. I desided to do a simple app with BEPUPhysics (using XNAFramework). Add some entity's and try to rotate it in the same way. To see, maybe I am doing well, but problem in client side diasplaying. I created this app using some classes from demos, loaded static mesh, but didn't found any way to rotate it, so, how I can do it?
Thanks.