예제 #1
0
 void OnEnable()
 {
     motionScript = (GlobalMove)gameObject.AddComponent ("GlobalMove");
     switch (motionModel){
         case motionModels.DISCRETE:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlDiscrete");
             motionScript.changeMotionModel(motionModels.DISCRETE);
        			break;
         case motionModels.KINEMATIC:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlKinematic");
             motionScript.changeMotionModel(motionModels.KINEMATIC);
             break;
         case motionModels.DYNAMIC:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlDynamic");
             motionScript.changeMotionModel(motionModels.DYNAMIC);
             break;
         case motionModels.DIFFERENTIAL:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlDifferential");
             motionScript.changeMotionModel(motionModels.DIFFERENTIAL);
             break;
         case motionModels.CAR:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlCar");
             motionScript.changeMotionModel(motionModels.CAR);
             break;
     }
 }
예제 #2
0
    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;
    }
예제 #3
0
 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> ();
 }
예제 #4
0
    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;
    }
예제 #5
0
 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);
 }