public byte[] Serialize(wheel wheel) { List <byte> DataStream = new List <byte>(); byte[] realwheel_base = Serialize(wheel.wheel_O); DataStream.AddRange(realwheel_base); byte[] realwheel_ext = Serialize(wheel.wheel_E); DataStream.AddRange(realwheel_ext); return(DataStream.ToArray()); }
void detachObjects(wheel wheel) { if (wheels[(int)wheel] != null) { //wheels[(int)wheel].SceneNode.PositionZ += 15; GameObject holder = new GameObject(); holder.SceneNode.Position = _GameObject.SceneNode.Position; holder.Parent = _GameObject.ActiveScene.Root; wheels[(int)wheel].Parent = holder; wheels[(int)wheel] = null; } }
// Use this for initialization void Start() { //Transform aChild = transform.FindChild("Cylinder"); //Wheel script = aChild.GetComponentInChildren<Wheel>(); //aChild.speed = 90; // aChild.gameObject. HingeJoint[] hingeJoints = GetComponentsInChildren <HingeJoint>(); wheel myscript = gameObject.GetComponentInChildren <wheel>(); myscript.speed = 90; //Debug.Log(hingeJoints.Length); // foreach (wheel joint in myscript) myscript.speed = 90; }
void Start() { initialVector = transform.position - piv1.transform.position; initialVector.y = 0; inipos = new Vector3(transform.position.x, road.transform.position.y - 0.8f, transform.position.z); this.transform.position = inipos; scr = GetComponentInChildren <wheel>(); }
void Start () { initialVector = transform.position - piv1.transform.position; initialVector.y = 0; inipos = new Vector3 (transform.position.x,road.transform.position.y-0.8f,transform.position.z); this.transform.position = inipos; scr=GetComponentInChildren<wheel>(); }
void Awake() { //make sure vehicleBody has the correct parent// vehicleBody.transform.SetParent(transform); //create physics body// physicsBody = new GameObject(gameObject.name + " physics"); physicsBody.transform.position = (wheelLeftBack.transform.position + wheelLeftFront.transform.position + wheelRightBack.transform.position + wheelRightFront.transform.position) / 4; physicsBody.transform.rotation = transform.rotation; transform.position = physicsBody.transform.position; //create a wheels holder wheels = new GameObject(gameObject.name + " wheels"); wheels.transform.position = physicsBody.transform.position; wheels.transform.rotation = physicsBody.transform.rotation; //create rigidbody// rbody = physicsBody.AddComponent <Rigidbody>(); rbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; rbody.mass = 100f; rbody.angularDrag = 5f; //set up the wheels// //rear left wheel// Mesh mesh = wheelLeftBack.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colLB = new GameObject("colLB"); SphereCollider col = colLB.AddComponent <SphereCollider>(); if (wheelLeftBack.transform.childCount > 0) { col.radius = (boundSize / 2f) * wheelLeftBack.transform.GetChild(0).transform.lossyScale.y; colLB.transform.position = wheelLeftBack.transform.position; } else { col.radius = (boundSize / 2f) * wheelLeftBack.transform.lossyScale.y; colLB.transform.position = wheelLeftBack.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colLB.transform.SetParent(physicsBody.transform); wheel wheelScript = colLB.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelLeftBack; wheelScript.wheelLB = true; wheelScript.wheelHangDistance = wheelHangDistance; wheelScript.tireTrailWidth = tireTrailWidth; wheelLeftBack.transform.SetParent(wheels.transform); //front left wheel// mesh = wheelLeftFront.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colLF = new GameObject("colLF"); col = colLF.AddComponent <SphereCollider>(); if (wheelLeftFront.transform.childCount > 0) { col.radius = (boundSize / 2f) * wheelLeftFront.transform.GetChild(0).transform.lossyScale.y; colLF.transform.position = wheelLeftFront.transform.position; } else { col.radius = (boundSize / 2f) * wheelLeftFront.transform.lossyScale.y; colLF.transform.position = wheelLeftFront.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colLF.transform.SetParent(physicsBody.transform); wheelScript = colLF.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelLeftFront; wheelScript.wheelLF = true; wheelScript.wheelHangDistance = wheelHangDistance; wheelScript.tireTrailWidth = tireTrailWidth; turnLF = new GameObject("turnLF"); turnLF.transform.SetParent(wheels.transform); turnLF.transform.position = wheelLeftFront.transform.position; turnLF.transform.rotation = wheels.transform.rotation; wheelLeftFront.transform.SetParent(turnLF.transform); wheelScript.turnObj = turnLF; wheelScript.frontTire = true; //rear right wheel// mesh = wheelRightBack.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colRB = new GameObject("colRB"); col = colRB.AddComponent <SphereCollider>(); if (wheelRightBack.transform.childCount > 0) { col.radius = (boundSize / 2f) * wheelRightBack.transform.GetChild(0).transform.lossyScale.y; colRB.transform.position = wheelRightBack.transform.position; } else { col.radius = (boundSize / 2f) * wheelRightBack.transform.lossyScale.y; colRB.transform.position = wheelRightBack.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colRB.transform.SetParent(physicsBody.transform); wheelScript = colRB.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelRightBack; wheelScript.wheelRB = true; wheelScript.wheelHangDistance = wheelHangDistance; wheelScript.tireTrailWidth = tireTrailWidth; wheelRightBack.transform.SetParent(wheels.transform); //front right wheel// mesh = wheelRightFront.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colRF = new GameObject("colRF"); col = colRF.AddComponent <SphereCollider>(); if (wheelRightFront.transform.childCount > 0) { col.radius = (boundSize / 2f) * wheelRightFront.transform.GetChild(0).transform.lossyScale.y; colRF.transform.position = wheelRightFront.transform.position; } else { col.radius = (boundSize / 2f) * wheelRightFront.transform.lossyScale.y; colRF.transform.position = wheelRightFront.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colRF.transform.SetParent(physicsBody.transform); wheelScript = colRF.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelRightFront; wheelScript.wheelRF = true; wheelScript.wheelHangDistance = wheelHangDistance; wheelScript.tireTrailWidth = tireTrailWidth; turnRF = new GameObject("turnRF"); turnRF.transform.SetParent(wheels.transform); turnRF.transform.position = wheelRightFront.transform.position; turnRF.transform.rotation = wheels.transform.rotation; wheelRightFront.transform.SetParent(turnRF.transform); wheelScript.turnObj = turnRF; wheelScript.frontTire = true; //create a body holder// suspensionBody = new GameObject(gameObject.name + " suspension"); suspensionBody.transform.position = physicsBody.transform.position; suspensionBody.transform.rotation = physicsBody.transform.rotation; jbody = suspensionBody.AddComponent <Rigidbody>(); jbody.useGravity = false; jbody.mass = 10f; jbody.drag = 1f; jbody.angularDrag = 2f; jbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; CharacterJoint joint = suspensionBody.AddComponent <CharacterJoint>(); joint.connectedBody = rbody; joint.axis = new Vector3(1f, 0f, 0f); joint.swingAxis = new Vector3(1f, 0f, 0f); joint.enablePreprocessing = false; joint.enableProjection = true; SoftJointLimitSpring temp = joint.twistLimitSpring; temp.spring = suspensionTension * 400f; temp.damper = 0.4f; joint.twistLimitSpring = temp; SoftJointLimit temp2 = joint.lowTwistLimit; temp2.limit = suspensionLengths.x * -1f; temp2.bounciness = 1f; joint.lowTwistLimit = temp2; SoftJointLimit temp3 = joint.highTwistLimit; temp3.limit = suspensionLengths.x; temp3.bounciness = 1f; joint.highTwistLimit = temp3; SoftJointLimitSpring temp4 = joint.swingLimitSpring; temp4.spring = suspensionTension * 400f; temp4.damper = 0.4f; joint.swingLimitSpring = temp4; SoftJointLimit temp5 = joint.swing1Limit; temp5.limit = suspensionLengths.y * 0.1f; temp5.bounciness = 1f; joint.swing1Limit = temp5; SoftJointLimit temp6 = joint.swing2Limit; temp6.limit = suspensionLengths.z; temp6.bounciness = 1f; joint.swing2Limit = temp6; //create body collider// colSuspension = new GameObject("colSuspension"); colSuspension.transform.position = suspensionBody.transform.position; colSuspension.transform.rotation = suspensionBody.transform.rotation; colSuspension.transform.SetParent(suspensionBody.transform); BoxCollider col2 = colSuspension.AddComponent <BoxCollider>(); float distX = Vector3.Distance(wheelLeftFront.transform.position, wheelRightFront.transform.position); float distZ = Vector3.Distance(wheelLeftFront.transform.position, wheelLeftBack.transform.position); col2.size = new Vector3(distX - (col.radius), (col.radius) * 0.5f, distZ + ((col.radius) * 2f)); col2.center = new Vector3(0f, col.radius, 0f); col2.material = bodyPhysicsMat; jbody.centerOfMass = col2.center + new Vector3(0f, col.radius * 0.5f, 0f); rbody.centerOfMass = col2.center + new Vector3(0f, -col.radius * 0.5f, 0f); defaultCOG = rbody.centerOfMass; colBody = new GameObject("colBody"); colBody.transform.position = physicsBody.transform.position; colBody.transform.rotation = physicsBody.transform.rotation; colBody.transform.SetParent(physicsBody.transform); BoxCollider col3 = colBody.AddComponent <BoxCollider>(); col3.size = new Vector3(distX - col.radius, col.radius * 0.5f, distZ); col3.center = new Vector3(0f, col.radius, 0f); col3.material = bodyPhysicsMat; }
void Awake() { Console.WriteLine("Connected to server..."); Instantiate(Resources.Load("Manager/CarCanvas", typeof(GameObject))); if (GameManager.mobileOn || GameManager.cameraOp) { Instantiate(Resources.Load("Manager/PlayerCameraMobile", typeof(GameObject))); } else if (!GameManager.mobileOn && !GameManager.cameraOp) { Instantiate(Resources.Load("Manager/PlayerCamera", typeof(GameObject))); } move = true; if (gameObject.name == "Vehicle07") { suspension = 0; } vehicleBody = GameObject.Find("Body"); wheelLeftFront = GameObject.Find("FLW"); wheelRightFront = GameObject.Find("FRW"); wheelLeftBack = GameObject.Find("BLW"); wheelRightBack = GameObject.Find("BRW"); tirePhysicsMat = GameObject.Find("TireP").GetComponent <BoxCollider>().material; bodyPhysicsMat = GameObject.Find("BodyP").GetComponent <BoxCollider>().material; //make sure vehicleBody has the correct parent// vehicleBody.transform.SetParent(transform); //create physics body// physicsBody = new GameObject(gameObject.name + " physics"); physicsBody.transform.position = (wheelLeftBack.transform.position + wheelLeftFront.transform.position + wheelRightBack.transform.position + wheelRightFront.transform.position) / 4; physicsBody.transform.rotation = transform.rotation; transform.position = physicsBody.transform.position; //create a wheels holder wheels = new GameObject(gameObject.name + " wheels"); wheels.transform.position = physicsBody.transform.position; wheels.transform.rotation = physicsBody.transform.rotation; //create rigidbody// rbody = physicsBody.AddComponent <Rigidbody>(); rbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; rbody.mass = 100f; rbody.angularDrag = 5f; //set up the wheels// //rear left wheel// Mesh mesh = wheelLeftBack.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colLB = new GameObject("colLB"); SphereCollider col = colLB.AddComponent <SphereCollider>(); if (wheelLeftBack.transform.childCount > 0) { col.radius = 1.5f; colLB.transform.position = wheelLeftBack.transform.position; } else { col.radius = 1.5f; colLB.transform.position = wheelLeftBack.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colLB.transform.SetParent(physicsBody.transform); wheel wheelScript = colLB.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelLeftBack; wheelScript.wheelLB = true; wheelScript.wheelHangDistance = wheelHangDistance; wheelLeftBack.transform.SetParent(wheels.transform); //front left wheel// mesh = wheelLeftFront.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colLF = new GameObject("colLF"); col = colLF.AddComponent <SphereCollider>(); if (wheelLeftFront.transform.childCount > 0) { col.radius = 1.5f; colLF.transform.position = wheelLeftFront.transform.position; } else { col.radius = 1.5f; colLF.transform.position = wheelLeftFront.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colLF.transform.SetParent(physicsBody.transform); wheelScript = colLF.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelLeftFront; wheelScript.wheelLF = true; wheelScript.wheelHangDistance = wheelHangDistance; turnLF = new GameObject("turnLF"); turnLF.transform.SetParent(wheels.transform); turnLF.transform.position = wheelLeftFront.transform.position; turnLF.transform.rotation = wheels.transform.rotation; wheelLeftFront.transform.SetParent(turnLF.transform); wheelScript.turnObj = turnLF; wheelScript.frontTire = true; //rear right wheel// mesh = wheelRightBack.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colRB = new GameObject("colRB"); col = colRB.AddComponent <SphereCollider>(); if (wheelRightBack.transform.childCount > 0) { col.radius = 1.5f; colRB.transform.position = wheelRightBack.transform.position; } else { col.radius = 1.5f; colRB.transform.position = wheelRightBack.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colRB.transform.SetParent(physicsBody.transform); wheelScript = colRB.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelRightBack; wheelScript.wheelRB = true; wheelScript.wheelHangDistance = wheelHangDistance; wheelRightBack.transform.SetParent(wheels.transform); //front right wheel// mesh = wheelRightFront.GetComponentInChildren <MeshFilter>().mesh; getDiameter(mesh); colRF = new GameObject("colRF"); col = colRF.AddComponent <SphereCollider>(); if (wheelRightFront.transform.childCount > 0) { col.radius = 1.5f; colRF.transform.position = wheelRightFront.transform.position; } else { col.radius = 1.5f; colRF.transform.position = wheelRightFront.transform.position + mesh.bounds.center; } col.material = tirePhysicsMat; col.center = new Vector3(0f, 0f, 0f); colRF.transform.SetParent(physicsBody.transform); wheelScript = colRF.AddComponent <wheel>(); wheelScript.vehicleObj = gameObject; wheelScript.wheelObj = wheelRightFront; wheelScript.wheelRF = true; wheelScript.wheelHangDistance = wheelHangDistance; turnRF = new GameObject("turnRF"); turnRF.transform.SetParent(wheels.transform); turnRF.transform.position = wheelRightFront.transform.position; turnRF.transform.rotation = wheels.transform.rotation; wheelRightFront.transform.SetParent(turnRF.transform); wheelScript.turnObj = turnRF; wheelScript.frontTire = true; //create a body holder// suspensionBody = new GameObject(gameObject.name + " suspension"); suspensionBody.transform.position = physicsBody.transform.position; suspensionBody.transform.rotation = physicsBody.transform.rotation; jbody = suspensionBody.AddComponent <Rigidbody>(); jbody.useGravity = false; jbody.mass = 10f; jbody.drag = 1f; jbody.angularDrag = 2f; jbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; CharacterJoint joint = suspensionBody.AddComponent <CharacterJoint>(); joint.connectedBody = rbody; joint.axis = new Vector3(1f, 0f, 0f); joint.swingAxis = new Vector3(1f, 0f, 0f); joint.enablePreprocessing = false; joint.enableProjection = true; SoftJointLimitSpring temp = joint.twistLimitSpring; temp.spring = suspensionTension * 4000f; temp.damper = 0.4f; joint.twistLimitSpring = temp; SoftJointLimit temp2 = joint.lowTwistLimit; temp2.limit = suspensionLengths.x * -0.5f; temp2.bounciness = 0.5f; joint.lowTwistLimit = temp2; SoftJointLimit temp3 = joint.highTwistLimit; temp3.limit = suspensionLengths.x; temp3.bounciness = 0.5f; joint.highTwistLimit = temp3; SoftJointLimitSpring temp4 = joint.swingLimitSpring; temp4.spring = suspensionTension * 3000f; temp4.damper = 0.1f; joint.swingLimitSpring = temp4; SoftJointLimit temp5 = joint.swing1Limit; temp5.limit = suspensionLengths.y * 0.1f; temp5.bounciness = 0.5f; joint.swing1Limit = temp5; SoftJointLimit temp6 = joint.swing2Limit; temp6.limit = suspensionLengths.z; temp6.bounciness = 0.5f; joint.swing2Limit = temp6; //create body collider// colSuspension = new GameObject("colSuspension"); colSuspension.transform.position = suspensionBody.transform.position; colSuspension.transform.rotation = suspensionBody.transform.rotation; colSuspension.transform.SetParent(suspensionBody.transform); BoxCollider col2 = colSuspension.AddComponent <BoxCollider>(); float distX = Vector3.Distance(wheelLeftFront.transform.position, wheelRightFront.transform.position); float distZ = Vector3.Distance(wheelLeftFront.transform.position, wheelLeftBack.transform.position); col2.size = new Vector3(distX - (col.radius), (col.radius) * 0.5f, distZ + ((col.radius) * 2f)); col2.center = new Vector3(0f, 2f, 0f); col2.material = bodyPhysicsMat; jbody.centerOfMass = col2.center + new Vector3(0f, col.radius * 0.5f, 0f); rbody.centerOfMass = col2.center + new Vector3(0f, -col.radius * 0.5f, 0f); defaultCOG = rbody.centerOfMass; colBody = new GameObject("colBody"); colBody.transform.position = physicsBody.transform.position; colBody.transform.rotation = physicsBody.transform.rotation; colBody.transform.SetParent(physicsBody.transform); BoxCollider col3 = colBody.AddComponent <BoxCollider>(); col3.size = new Vector3(distX - col.radius, col.radius * 0.5f, distZ + 10); col3.center = new Vector3(0f, col.radius, 0f); col3.material = bodyPhysicsMat; Engine = GameObject.Find("EngineSound").GetComponent <AudioSource>(); Nitro = GameObject.Find("NitroSound").GetComponent <AudioSource>(); FireIgnition = GameObject.Find("FireIgnitionSound").GetComponent <AudioSource>(); Tire = GameObject.Find("TireSound").GetComponent <AudioSource>(); }