Traffic Racing Template project was created for wide range of Unity developers. It fits perfectly with needs of a small independent developer studio and a global game publisher company. This template contains all necessary features to get started with. No information is available for this page.Learn why.
This is a sample project greate by unity3d. There are two scenes in project.I'm a green hand in U3D, just create for learning.
FirstScene
This is a sample scene for ball control. Control a ball to move in fence, you can find sample code for keyboard control.
CarScene
This scene contains a controllable car model and some cartographic models. You can control a car to run normally.
This scene also support mobile touch control, implemented by EasyTouch.
How to Run
Whole project was uploaded. Just import it and run.
Any questions please open new issues, or email me drictly [email protected] to communicate with each other.
Any suggestions how to pan/tilt an object at the center of the screen using using an external (accelerometer) sensor? I can't get it to stay on screen, and get all kinds of weird artifacts like drifting, gimbal lock and cross-contamination on the axis that I didn't want to change!
This is how I was trying to move it:
void SetPosByAngle ( float fPitch, float fRoll )
{
Vector3 LowerLimit = new Vector3(0, 0, 0);
Vector3 UpperLimit = new Vector3(180, 180, 180);
// Normalize from -180/+180 to -1/+1
fPitch = (fPitch) / 180.0f;
fRoll = (fRoll) / 180.0f;
Vector3 AngleDiff = UpperLimit - LowerLimit;
Vector3 CalculatedAngle = new Vector3(-fPitch * AngleDiff.y, 0, -fRoll * AngleDiff.x);
TragetAngle = LowerLimit + CalculatedAngle;
transform.localEulerAngles = TragetAngle;
transform.localEulerAngles = TragetAngle;
}
Where the angles sent to the function above are calculated via:
fPitch = (float) (Math.Atan2(YAxisAccelerationData,ZAxisAccelerationData)+M_PI)*RAD_TO_DEG;
fRoll = (float) (Math.Atan2(ZAxisAccelerationData, XAxisAccelerationData)+M_PI)*RAD_TO_DEG;
I've read some people have had luck creating an artificial horizon.. they project a fixed vector and a variable one onto a common X/Z plane, then they apply the yaw ,for example, around the global axis instead of the object's axis. Although I've read even this isn't perfect, and it's better to use local rotations to update the forward vector together with a reference up vector to build the final orientation.
Unfortunately, I haven't seen an actual implementation for any of this... I understand only 2 angles (pitch,yaw, or roll) can be derived from a 3-axis acclerometer, but what does the unity code look like transform.rotate,LookRotation,ProjectOnPlane, Quaternion.Euler, etc?