public virtual void Init() { // Cache the usual suspects iRigid = GetComponent <Rigidbody>(); iGameobject = gameObject; iTransform = transform; // Add default keyboard input default_input = iGameobject.GetComponent <Keyboard_Input>(); // Cache a reference to player controller PlayerController = iGameobject.GetComponent <BasePlayerManager>(); // Call base class init PlayerController.Init(); // With this simple vehicle code, we set the center of mass low to try to keep the car from toppling over iRigid.centerOfMass = new Vector3(0, -4f, 0); // See if we cant find an engine sound source, if we need to if (engineSoundSource == null) { engineSoundSource = iGameobject.GetComponent <AudioSource>(); } }
public virtual void Init() { // cache te usual suspects iRigid = GetComponent <Rigidbody>(); iGameobject = gameObject; iTransform = transform; // add default keyboard input default_input = iGameobject.AddComponent <Keyboard_Input>(); // cache a reference to the player controller iPlayerController = iGameobject.GetComponent <BasePlayerManager>(); if (iPlayerController != null) { iPlayerController.Init(); } }
public virtual void Init() { myRigrdBody = rigidbody; myTransform = transform; myGameObject = gameObject; default_input = myGameObject.AddComponent <Keyboard_Input> (); myPlayerController = myGameObject.GetComponent <BasePlayerManager> (); if (myPlayerController != null) { myPlayerController.Init(); } }
public virtual void Init() { // cache the usual suspects myBody = GetComponent <Rigidbody>(); myGO = gameObject; myTransform = transform; // add default keyboard input default_input = myGO.AddComponent <Keyboard_Input>(); // cache a reference to the player controller myPlayerController = myGO.GetComponent <BasePlayerManager>(); if (myPlayerController != null) { myPlayerController.Init(); } }
public virtual void Init() { myRigrdBody = rigidbody; myGameObject = gameObject; myTransform = transform; default_input = myGameObject.AddComponent <Keyboard_Input>(); myPlayerController = myGameObject.GetComponent <BasePlayerManager>(); myPlayerController.Init(); myRigrdBody.centerOfMass = new Vector3(0, -4f, 0); if (engineSound == null) { engineSound = myGameObject.GetComponent <AudioSource>(); } }
// main logic public override void Init() { base.Init(); // add default keyboard input if (!default_input) { default_input = myGO.AddComponent <Keyboard_Input> (); } // cache a reference to the player controller if (!myPlayerController) { myPlayerController = myGO.GetComponent <BasePlayerManager> (); } if (myPlayerController != null) { myPlayerController.Init(); } }
public virtual void Init() { Debug.Log("BaseVehicle Init called."); // cache the usual suspects myBody = GetComponent <Rigidbody>(); myGO = gameObject; myTransform = transform; // add default keyboard input if (myGO.GetComponent <Keyboard_Input>() == null) { default_input = myGO.AddComponent <Keyboard_Input>(); } // cache a reference to the player controller myPlayerController = myGO.GetComponent <BasePlayerManager>(); // call base class init myPlayerController.Init(); // with this simple vehicle code, we set the center of mass low to try to keep the car from toppling over myBody.centerOfMass = new Vector3(0, -4f, 0); // see if we can find an engine sound source, if we need to if (engineSoundSource == null) { engineSoundSource = myGO.GetComponent <AudioSource>(); } // now lets copy over our friction and suspension values to the wheels (keeping these values in one place // rather than having to change them on each wheel is a neater way to work!) // set up curves for front and sideways values WheelFrictionCurve curveF = new WheelFrictionCurve(); curveF.extremumSlip = forwardFrictionExtremumSlip; curveF.extremumValue = forwardFrictionExtremumValue; curveF.asymptoteSlip = forwardFrictionAsymptoteSlip; curveF.asymptoteValue = forwardFrictionAsymptoteValue; curveF.stiffness = forwardFrictionStiffnessFactor; WheelFrictionCurve curveS = new WheelFrictionCurve(); curveS.extremumSlip = sidewaysFrictionExtremumSlip; curveS.extremumValue = sidewaysFrictionExtremumValue; curveS.asymptoteSlip = sidewaysFrictionAsymptoteSlip; curveS.asymptoteValue = sidewaysFrictionAsymptoteValue; curveS.stiffness = sidewaysFrictionStiffnessFactor; // set up JointSpring for the suspension settings JointSpring suspensionJointSpring = new JointSpring(); suspensionJointSpring.damper = suspensionDamper; suspensionJointSpring.spring = suspensionSpring; // front left frontWheelLeft.mass = wheelMass; frontWheelLeft.radius = wheelRadius; frontWheelLeft.suspensionDistance = suspensionDistance; frontWheelLeft.suspensionSpring = suspensionJointSpring; frontWheelLeft.forwardFriction = curveF; frontWheelLeft.sidewaysFriction = curveS; // front right frontWheelRight.mass = wheelMass; frontWheelRight.radius = wheelRadius; frontWheelRight.suspensionDistance = suspensionDistance; frontWheelRight.suspensionSpring = suspensionJointSpring; frontWheelRight.forwardFriction = curveF; frontWheelRight.sidewaysFriction = curveS; // rear left rearWheelLeft.mass = wheelMass; rearWheelLeft.radius = wheelRadius; rearWheelLeft.suspensionDistance = suspensionDistance; rearWheelLeft.suspensionSpring = suspensionJointSpring; rearWheelLeft.forwardFriction = curveF; rearWheelLeft.sidewaysFriction = curveS; // rear right rearWheelRight.mass = wheelMass; rearWheelRight.radius = wheelRadius; rearWheelRight.suspensionDistance = suspensionDistance; rearWheelRight.suspensionSpring = suspensionJointSpring; rearWheelRight.forwardFriction = curveF; rearWheelRight.sidewaysFriction = curveS; Debug.Log("BaseVehicle wheels setup and Init() complete."); }