Exemplo n.º 1
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);
        collisionAvoidance = currentObject.AddComponent<LocalCollisionAvoidance> ();
        collisionAvoidance.motionModel = _motionModel;
        this.motionModel = _motionModel;
        return currentObject;
    }
Exemplo n.º 2
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;
    }