예제 #1
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == "Planet")
     {
         attractor = collision.gameObject.GetComponent <GravityAttractor>();
     }
 }
예제 #2
0
 public void SetAttractor(GravityAttractor _attractor)
 {
     if ((_attractor != null && !canLeave) || canLeave)
     {
         attractor = _attractor;
     }
 }
예제 #3
0
    void Start()
    {
        this.planet = Player.Instance.getPlanetNavigation().GetComponent<GravityAttractor>();
        this.rb = this.GetComponent<Rigidbody>();

        this.rb.useGravity = false;
    }
 void Awake()
 {
     planet = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityAttractor>();
     GetComponent <Rigidbody>().useGravity  = false;
     GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
     //don't want rigid bodies to do its own rotation
 }
예제 #5
0
 void OnTriggerExit(Collider col)
 {
     if (col.gameObject.tag == "Planet" && !beingControlled)
     {
         planet = null;
     }
 }
예제 #6
0
 //disabling all the nesasary rigidbody components to allow it to move on its own
 void Awake()
 {
     planet                = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityAttractor>();
     rigidbody             = GetComponent <Rigidbody>();
     rigidbody.useGravity  = false;
     rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
 }
예제 #7
0
 void OnTriggerExit(Collider col)
 {
     if (col.CompareTag("Planet"))
     {
         attractor = null;
     }
 }
예제 #8
0
    void SpawnAttractor()
    {
        GravityAttractor prefab = attractorPrefabs[Random.Range(0, attractorPrefabs.Length)];
        GravityAttractor spawn  = Instantiate <GravityAttractor>(prefab);

        spawn.transform.localPosition = Random.onUnitSphere * spawnDistance;
    }
예제 #9
0
	void Awake () {
		currentGravityObject = GameObject.FindGameObjectWithTag("StartingGravityPoint").GetComponent<GravityAttractor>();
		rigidbody = GetComponent<Rigidbody> ();

		rigidbody.useGravity = false;
		rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
	}
예제 #10
0
 private void Awake()
 {
     _planet         = GameObject.FindGameObjectWithTag("World").GetComponent <GravityAttractor>();
     _rb             = GetComponent <Rigidbody>();
     _rb.useGravity  = false;
     _rb.constraints = RigidbodyConstraints.FreezeRotation;
 }
예제 #11
0
    void Start()
    {
        this.planet = Player.Instance.getPlanetNavigation().GetComponent <GravityAttractor>();
        this.rb     = this.GetComponent <Rigidbody>();

        this.rb.useGravity = false;
    }
예제 #12
0
    //FixedUpdate gets called at a regular interval independent from the framerate
    void FixedUpdate()
    {
        if (planetGravity)
        {
            targetGravity = targetPlanet.GetComponent <GravityAttractor> ();
            targetGravity.Attract(transform);
        }
        else
        {
            // Apply downwards gravity to body
            transform.GetComponent <Rigidbody> ().AddForce(gravityUp * gravity);
            // Allign bodies up axis with the centre of planet
            Quaternion targetRotation = Quaternion.FromToRotation(transform.up, gravityUp) * transform.rotation;
            float      angularSpeed   = 3.0f;
            if (transform.rotation != targetRotation)
            {
                //transform.rotation = Quaternion.Lerp (transform.rotation, targetRotation, angularSpeed);

                transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, angularSpeed);
                //print("Player: " + transform.rotation + ", target: " + targetRotation);
                //transform.Rotate(0, yAmount, 0, Space.Self);
            }
        }
        //linear interpolation
        //Zielposition über Zeitraum
    }
예제 #13
0
    void Awake()
    {
        planet = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityAttractor>();

        // Disable rigidbody gravity and rotation as this is simulated in GravityAttractor script
        rigidbody.useGravity  = false;
        rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #14
0
    void Awake()
    {
        currentGravityObject = GameObject.FindGameObjectWithTag("StartingGravityPoint").GetComponent <GravityAttractor>();
        rigidbody            = GetComponent <Rigidbody> ();

        rigidbody.useGravity  = false;
        rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #15
0
	void Awake () {
		planet = GameObject.FindGameObjectWithTag("Planet").GetComponent<GravityAttractor>();
		rigidbody = GetComponent<Rigidbody> ();

		// Disable rigidbody gravity and rotation as this is simulated in GravityAttractor script
		rigidbody.useGravity = false;
		rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
	}
예제 #16
0
    void Awake()
    {
        thisRigidBody = GetComponent <Rigidbody> ();

        thisRigidBody.useGravity  = false;
        thisRigidBody.constraints = RigidbodyConstraints.FreezeRotation;
        planet = GetComponentInParent <GravityAttractor> ();
    }
예제 #17
0
 void Start()
 {
     planet_script_         = planet_.GetComponent <GravityAttractor>();
     controller_script_     = GetComponent <PlayerSphericalGravityController>();
     rigidbody_             = GetComponent <Rigidbody>();
     rigidbody_.useGravity  = false;
     rigidbody_.constraints = RigidbodyConstraints.FreezeRotation;
 }
예제 #18
0
    private void Awake()
    {
        attractor = GameObject.FindGameObjectWithTag("Attractor").GetComponent <GravityAttractor>();
        body      = GetComponent <Rigidbody>();

        body.useGravity  = false;
        body.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #19
0
    void Start()
    {
        attractor = FindObjectOfType <GravityAttractor> ();
        GetComponent <Rigidbody>().useGravity  = false;
        GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;

        myTransform = transform;
    }
 void Awake()
 {
     planet = GameObject.FindGameObjectWithTag("Planet").GetComponent<GravityAttractor>();
     if (GetComponent<Rigidbody2D>())
     {
         GetComponent<Rigidbody2D>().gravityScale = 0;
         GetComponent<Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
     }
 }
예제 #21
0
    void Awake()
    {
        attractor = GameObject.FindGameObjectWithTag("Attractor").GetComponentInChildren <GravityAttractor>();
        rb        = GetComponent <Rigidbody>();

        // Disable rigidbody gravity and rotation as this is simulated in GravityAttractor script
        rb.constraints = RigidbodyConstraints.FreezeRotation;
        rb.useGravity  = false;
    }
예제 #22
0
    private void WallDetect()
    {
        RaycastHit objectHit;

        //Up
        if (Physics.Raycast(transform.position, transform.up, out objectHit, 0.5f))
        {
            if (objectHit.transform.tag == "Wall")
            {
                gravityAttractor = objectHit.transform.GetComponent <GravityAttractor>();
            }
        }

        //Forward
        else if (Physics.Raycast(transform.position, transform.forward, out objectHit, wallDetection))
        {
            if (objectHit.transform.tag == "Wall")
            {
                gravityAttractor = objectHit.transform.GetComponent <GravityAttractor>();
            }
        }

        //Right
        else if (Physics.Raycast(transform.position, transform.right, out objectHit, wallDetection))
        {
            if (objectHit.transform.tag == "Wall")
            {
                gravityAttractor = objectHit.transform.GetComponent <GravityAttractor>();
            }
        }

        //Back
        else if (Physics.Raycast(transform.position, -transform.forward, out objectHit, wallDetection))
        {
            if (objectHit.transform.tag == "Wall")
            {
                gravityAttractor = objectHit.transform.GetComponent <GravityAttractor>();
            }
        }

        //Left
        else if (Physics.Raycast(transform.position, -transform.right, out objectHit, wallDetection))
        {
            if (objectHit.transform.tag == "Wall")
            {
                gravityAttractor = objectHit.transform.GetComponent <GravityAttractor>();
            }
        }
        //Down
        else if (Physics.Raycast(transform.position, -transform.up, out objectHit, wallDetection))
        {
            if (objectHit.transform.tag == "Wall")
            {
                gravityAttractor = objectHit.transform.GetComponent <GravityAttractor>();
            }
        }
    }
예제 #23
0
    void Start()
    {
        _body = GetComponent <Rigidbody>();

        if (attractor == null)
        {
            attractor = GameObject.FindGameObjectWithTag("Attractor").GetComponent <GravityAttractor>();
        }
    }
예제 #24
0
    void Awake()
    {
        centerSphere = GameObject.FindGameObjectWithTag("CenterSphere").GetComponent <GravityAttractor>();
        rigidBody    = GetComponent <Rigidbody>();
        t            = GetComponent <Transform>();

        rigidBody.useGravity  = false;
        rigidBody.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #25
0
    void OnTriggerEnter(Collider col)
    {
        GravityAttractor obj = col.GetComponent("GravityAttractor") as GravityAttractor;

        if (obj)
        {
            attractor = obj;
        }
    }
예제 #26
0
 void Start()
 {
     gravityAttractor = GetComponent<GravityAttractor> ();
     sphereCollider = GetComponent<SphereCollider> ();
     hideFrontPlanetFaceOnEnter = GetComponentInChildren<HideFrontPlanetFaceOnEnter> ();
     if(hideFrontPlanetFaceOnEnter!=null){
         hasInsidePlanet = true;
     }
     initialize ();
 }
예제 #27
0
    public void ChangePlanetAttractedTo()
    {
        GameObject newPlanet = GameController.instance.planets[FindClosestPlanet()];

        if (planetAttractedTo != newPlanet)
        {
            planetAttractedTo = newPlanet;
            planetScript      = planetAttractedTo.GetComponent <GravityAttractor>();
        }
    }
예제 #28
0
    private void Awake()
    {
        settings = FindObjectOfType <GameSettings>();
        planet   = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityAttractor>();

        rb = GetComponent <Rigidbody>();

        rb.useGravity  = false;
        rb.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #29
0
	void Awake () {
		planet = GameObject.FindGameObjectWithTag("Planet").GetComponent<GravityAttractor>();
		rigidbody = GetComponent<Rigidbody2D> ();

		// Disable rigidbody gravity and rotation as this is simulated in GravityAttractor script
		rigidbody.gravityScale = 0;
		rigidbody.fixedAngle = true;

		gravityCentre = planet.transform.position;
	}
예제 #30
0
 void Start()
 {
     gravityAttractor           = GetComponent <GravityAttractor> ();
     sphereCollider             = GetComponent <SphereCollider> ();
     hideFrontPlanetFaceOnEnter = GetComponentInChildren <HideFrontPlanetFaceOnEnter> ();
     if (hideFrontPlanetFaceOnEnter != null)
     {
         hasInsidePlanet = true;
     }
     initialize();
 }
예제 #31
0
    void Awake()
    {
        planet    = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityAttractor>();
        rigidbody = GetComponent <Rigidbody2D> ();

        // Disable rigidbody gravity and rotation as this is simulated in GravityAttractor script
        rigidbody.gravityScale = 0;
        rigidbody.fixedAngle   = true;

        gravityCentre = planet.transform.position;
    }
예제 #32
0
    void Awake()
    {
        GameObject planet = GameObject.FindGameObjectWithTag(Tags.Planet);

        attractor = planet.GetComponent <GravityAttractor>();

        Rigidbody rigidBody = GetComponent <Rigidbody>();

        rigidBody.useGravity  = false;
        rigidBody.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #33
0
    void Awake()
    {
        // Get the planet object if i tag it with planet
        planet = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityAttractor>();
        rb     = GetComponent <Rigidbody>();

        // Disable normal gravity and use the gravity created with my code
        rb.useGravity = false;
        // Makes the body not rotate normally only make it change if i tell it to
        rb.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #34
0
    void Awake()
    {
        //Started to use tags, they are the best.
        planet    = GameObject.FindGameObjectWithTag("Planet").GetComponent <GravityAttractor>();
        rigidbody = GetComponent <Rigidbody> ();

        // We have our own gravity...kind of the whole point. Disabling the in built gravity is required.
        rigidbody.useGravity = false;
        //Same as before, we want to do our own rotation.
        rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
    }
예제 #35
0
 void OnTriggerEnter(Collider col)
 {
     if (col.gameObject.tag == "Planet" && !beingControlled)
     {
         planet = col.gameObject.GetComponent <GravityAttractor> ();
         if (this.gameObject.layer == 8)
         {
             //this.transform.SetParent (col.transform);
         }
     }
 }
예제 #36
0
 private void Awake()
 {
     m_Transform             = GetComponent <Transform>();
     m_Rigidbody             = GetComponent <Rigidbody>();
     m_CenterSphere          = GameObject.FindGameObjectWithTag("CenterSphere").GetComponent <GravityAttractor>();
     m_GameController        = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>();
     m_Camera                = m_Transform.Find("Camera").gameObject.GetComponent <CameraController>();
     m_RadarCamera           = m_Transform.Find("RadarCamera").gameObject.GetComponent <CameraController>();
     m_StatusEffect["Slow"]  = 0.0f;
     m_Rigidbody.useGravity  = false;
     m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
     m_PowerUpSlot           = null;
 }
예제 #37
0
 void SetClosestAttractor()
 {
     if (attractors == null || attractors.Length < 1) {
         return;
     }
     GravityAttractor closestAttractor = attractors[0];
     for (int i = 1; i < attractors.Length; i++) {
         Vector3 curPosition = gameObject.transform.position;
         float curDistance = Vector3.Distance(curPosition, closestAttractor.transform.position);
         float tempDistance = Vector3.Distance(curPosition, attractors[i].transform.position);
         if (tempDistance < curDistance) {
             closestAttractor = attractors[i];
         }
     }
     curAttractor = closestAttractor;
 }
예제 #38
0
 public void SetPlanetGravity(GravityAttractor _planetGravity)
 {
     planetGravity = _planetGravity;
 }
예제 #39
0
 /**
    * Finds the first attractor within this object.
    */
 void Awake()
 {
     attractor = GetComponentInChildren<GravityAttractor>();
 }
예제 #40
0
 // Quick implementation of the gravity law, because we're awesome.
 private Vector3 Attraction(GravityAttractor attractor) {
     Vector3 r = myBody.position - attractor.transform.position;
     Vector3 result = ((reasonableG * myBody.mass * attractor.mass) / Mathf.Pow(r.magnitude, 2f)) * r.normalized;
     return result;
 }
예제 #41
0
 void Awake()
 {
     planet = GameObject.FindGameObjectWithTag("Planet").GetComponent<GravityAttractor>();
 }
예제 #42
0
 public void GetAttracted(GravityAttractor newPlanet)
 {
     planet = newPlanet;
 }