void Start() { AxleFront.Init(Rigidbody2D, WheelBase); AxleRear.Init(Rigidbody2D, WheelBase); TrackWidth = Vector2.Distance(AxleRear.TireLeft.transform.position, AxleRear.TireRight.transform.position); }
void Start() { AxleFront.Init(Rigidbody2D, WheelBase); AxleRear.Init(Rigidbody2D, WheelBase); TrackWidth = Mathf.Abs(AxleRear.TireLeft.transform.position.x - AxleRear.TireRight.transform.position.x); }
void Start() { joystick = FindObjectOfType <Joystick>(); joyButton = FindObjectOfType <JoyButton>(); AxleFront.Init(Rigidbody2D, WheelBase); AxleRear.Init(Rigidbody2D, WheelBase); TrackWidth = Mathf.Abs(AxleRear.TireLeft.transform.position.x - AxleRear.TireRight.transform.position.x); }
private void GenerateVehicle() { //VehicleSpawner.SpawnVehicle (this);//TODO GameObject vehicleObject = new GameObject("Vehicle " + m_presetName); if (Camera.current != null) { vehicleObject.transform.position = (Camera.current.transform.position + (Camera.current.transform.forward * 10f)); } else { vehicleObject.transform.position = Vector3.zero; } //RIGID_BODY///////////////////////////////////////////////////////////////// Rigidbody rigidBody = vehicleObject.AddComponent <Rigidbody> (); //TODO make this data driven rigidBody.mass = m_mass; rigidBody.drag = 0f; rigidBody.angularDrag = 0f; rigidBody.useGravity = true; rigidBody.isKinematic = false; rigidBody.interpolation = RigidbodyInterpolation.Interpolate; rigidBody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; rigidBody.constraints = RigidbodyConstraints.None; //VEHICLE///////////////////////////////////////////////////////////////// //ENGINE///////////////////////////////////////////////////////////////// Vehicle vehicle = vehicleObject.AddComponent <Vehicle>(); Drive engine = vehicleObject.AddComponent <Drive>(); vehicle.Init(this); //VIEW///////////////////////////////////////////////////////////////// GameObject viewObject = new GameObject("View"); viewObject.transform.SetParent(vehicleObject.transform, false); View view = viewObject.AddComponent <View> (); GameObject chassisObject = Instantiate(m_chassisPrefab, view.transform); Chassis chassis = chassisObject.GetComponent <Chassis>(); if (chassis == null) { Debug.LogError("No chassis component found"); } //AXLES///////////////////////////////////////////////////////////////// GameObject axlesObject = new GameObject("Axles"); axlesObject.transform.SetParent(vehicleObject.transform, false); List <Axle> axles = new List <Axle>(); //foreach (AxleData axleData in m_axles) for (int i = 0; i < m_axles.Count; i++) { GameObject axleObject = new GameObject(m_axles[i].Name); axleObject.transform.SetParent(axlesObject.transform, false); Axle axle = axleObject.AddComponent <Axle> (); axles.Add(axle); List <Wheel> wheels = new List <Wheel>(); //WHEELS///////////////////////////////////////////////////////////////// for (int j = 0; j < m_axles[i].WheelCount; j++) { GameObject wheelObject = new GameObject(m_axles[i].Name + j); wheelObject.transform.SetParent(axleObject.transform, false); if (i == 0) //front { wheelObject.transform.position = chassis.ForwardAxleOffset + (Vector3.right * (-(m_axles[i].AxleWidth * 0.5f) + (j * m_axles[i].AxleWidth))); } else if (i == 1) //rear //TODO make more robust to work with chassis { wheelObject.transform.position = chassis.RearAxleOffset + (Vector3.right * (-(m_axles[i].AxleWidth * 0.5f) + (j * m_axles[i].AxleWidth))); } Wheel wheel = wheelObject.AddComponent <Wheel> (); wheel.Init(this, m_axles[i]); wheels.Add(wheel); } axle.Init(this, m_axles[i], wheels); } engine.Init(this, vehicle.VehicleInput, axles); vehicleObject.transform.position = m_spawnPosition; }