public void Move(float xrate,float yrate, bool crouch, bool jump)
{
// If the player should jump...
/*
if (grounded && jump&&transform.parent==null)
{
// Add a vertical force to the player.
grounded = false;
rigidBody.AddForce(new Vector3(0f, jumpSpeed,0));
}
*/
// handle grounded
numGroundedTo = 0;
/*for (int i=0; i<numCollidingWith; ++i) {
string str="";
PhysicMaterial mat = collidingWith[i].collider.material;
foreach (PropertyDescriptor desc in TypeDescriptor.GetProperties(mat))
str += desc.Name+"="+desc.GetValue(mat);
print("colliding with: "+str);
}*/
for (int i=0; i<numCollidingWith; ++i)
if (collidingWith[i].impulse.y>0)
groundedTo[numGroundedTo++] = collidingWith[i];
numCollidingWith = 0;
if (transform.parent == null)
{
float mult = (numGroundedTo>0?1:0.1f);
for (int i=0; i<numGroundedTo; ++i)
if (groundedTo[i].gameObject.GetComponent<Collider>().material.bounciness>0.01f)
mult = 0.1f;
rigidBody.velocity -= Time.fixedDeltaTime*Vector3.right*(acceleration*rigidBody.velocity.x/maxSpeed)*mult;
rigidBody.velocity += Time.fixedDeltaTime*Vector3.right*xrate*acceleration*mult;
rigidBody.velocity += Time.fixedDeltaTime*(1-inwater.densityRatio)*Physics.gravity;
float f = Time.fixedDeltaTime*(inwater.thicknessRatio-1);
rigidBody.velocity = f*inwater.flow + (1-f)*rigidBody.velocity;
rigidBody.velocity += Time.fixedDeltaTime*inwater.flow*inwater.thicknessRatio;
transform.Rotate(Vector3.back, Time.fixedDeltaTime*rigidBody.velocity.x*180/Mathf.PI/localRadius);
}else
{
// rotate this, move this around the center
float lastRotVel = rotVel;
rotVel += Time.fixedDeltaTime*xrate*acceleration/(transform.position-transform.parent.position).magnitude;
rotVel -= Time.fixedDeltaTime*(acceleration*rotVel/maxSpeed);
//print(rotVel);
Vector3 pos = transform.position;
transform.Rotate(Vector3.back * Time.fixedDeltaTime*rotVel*180/Mathf.PI);
Vector3 temp=transform.position;
transform.RotateAround(transform.parent.position, Vector3.back, Time.fixedDeltaTime*(rotVel)*180/Mathf.PI);
//print("moved "+(transform.position-pos).magnitude/Time.fixedDeltaTime);
//print("speed: "+(transform.position-temp).magnitude/Time.fixedDeltaTime+", expected speed: "+rotVel+"ratio: "+(transform.position-temp).magnitude/Time.fixedDeltaTime/rotVel+", radius: "+radius);
// apply forces of acceleration and gravity to the parent
EnviroGear gear = transform.parent.GetComponent<EnviroGear>();
Rigidbody rigidBody2 = gear.GetComponent<Rigidbody>();
gear.angularMomentum += mass*(lastRotVel-rotVel) - 9.81f*0.1f*Vector3.Dot(Vector3.right, transform.position-transform.parent.position);
if (gear.isMovable)
rigidBody2.velocity += Vector3.down*9.81f*mass;
//rigidBody2.velocity += Vector3.left*(9.81f*0.1f*Vector3.Dot(Vector3.left, transform.position-transform.parent.position));
//gear.angularMomentum += 200*(xrate-rotVel)*mass*radius - 9.81f*0.1f*Vector3.Dot(Vector3.right, (transform.position-transform.parent.position));
//rigidBody2.velocity += Vector3.right*0;
}
int ii = -1;
foreach (GameObject go in gearChildren) {
go.transform.Rotate(rigidBody.angularVelocity*ii);
ii*=-1;
}
/*
if (!engaged)
m_Rigidbody.AddForce (Vector3.right * xrate * m_MaxSpeed);
else
transform.Rotate (Vector3.forward * m_MaxSpeed);
*/
}