GameObject instatiateNewRobot(GameObject prefab,GlobalControl.motionModels _motionModel) { Vector3 currentPosition = currentObject.transform.position; Quaternion currentRotation = currentObject.transform.rotation; //Remove current object DestroyImmediate(currentObject); //Create new one currentObject = (GameObject)Object.Instantiate(prefab,currentPosition,currentRotation); currentObject.name = robotName; currentObject.gameObject.SetActive(true); //Add control script gm = currentObject.gameObject.AddComponent<GlobalMove>(); gm.changeMotionModel (_motionModel); move = currentObject.AddComponent<moveTo> (); move.changeMotionModel (_motionModel); this.motionModel = _motionModel; return currentObject; }
public void createRobot() { print ("CREATING ROBOT: " + motionModel); if (robot != null){ GameObject.DestroyImmediate(robot); } switch(motionModel){ case GlobalControl.motionModels.DISCRETE: robot = (GameObject) Instantiate(Resources.Load("SphereCamera", typeof(GameObject))); break; case GlobalControl.motionModels.KINEMATIC: robot = (GameObject) Instantiate(Resources.Load("SphereCamera", typeof(GameObject))); break; case GlobalControl.motionModels.DYNAMIC: robot = (GameObject) Instantiate(Resources.Load("SphereCamera", typeof(GameObject))); break; case GlobalControl.motionModels.DIFFERENTIAL: robot = (GameObject) Instantiate(Resources.Load("DifferentialRobotCamera", typeof(GameObject))); robot.transform.localScale = new Vector3(0.3f,0.3f,0.3f); break; case GlobalControl.motionModels.CAR: robot = (GameObject) Instantiate(Resources.Load("CarCamera", typeof(GameObject))); break; } //Sample a position bool found = false; float x=0, z=0; while (!found) { x = Random.Range(-xBound,xBound); z = Random.Range(-yBound,yBound); found = !grid.isRectOccupied(new Vector3(x,0.5f,z),robot.collider.bounds.extents); } robot.transform.position = new Vector3(x, 0.5f, z); robot.transform.rotation = Quaternion.identity; robot.name = "robot"; robot.tag = "robot"; robot.SetActive (true); GameObject rCam = GameObject.Find ("RobotCamera"); rCam.camera.enabled = false; rCam.camera.gameObject.AddComponent<CameraControl> (); //Add MoveTo script moveComponent =robot.gameObject.AddComponent<GlobalMove> (); moveComponent.changeMotionModel (motionModel); moveComponent.changeMaxVelocity (maxV); if (motionModel == GlobalControl.motionModels.DIFFERENTIAL) { MoveDifferential md = robot.gameObject.GetComponent<MoveDifferential>(); md.maxW = 0.1f; } moveToComponent=robot.gameObject.AddComponent<moveTo> (); moveToComponent.changeMotionModel(motionModel); // robot.gameObject.AddComponent<LocalCollisionAvoidance> (); }
void Start() { //Create Sphere gtext.text = "Kinematic"; Vector3 initialPosition = new Vector3 (0, 0.5f, 0); currentObject = (GameObject)Object.Instantiate (sphere, initialPosition, Quaternion.identity); currentObject.gameObject.SetActive (true); currentObject.name = robotName; Rigidbody r = currentObject.gameObject.AddComponent<Rigidbody> (); r.constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ; //Add control script gm = currentObject.gameObject.AddComponent<GlobalMove>(); gm.changeMotionModel (motionModel); move = currentObject.AddComponent<moveTo> (); move.changeMotionModel (motionModel); collisionAvoidance = currentObject.AddComponent<LocalCollisionAvoidance> (); collisionAvoidance.motionModel = motionModel; }
void Start() { //Create Sphere gtext.text = "Kinematic"; Vector3 initialPosition = new Vector3 (0, 0.5f, 0); currentObject = (GameObject)Object.Instantiate (sphere, initialPosition, Quaternion.identity); currentObject.gameObject.SetActive (true); currentObject.name = robotName; //Add control script gm = currentObject.gameObject.AddComponent<GlobalMove>(); gm.changeMotionModel (motionModel); move = currentObject.AddComponent<moveTo> (); move.changeMotionModel (motionModel); }