Exemplo n.º 1
0
    void Update()
    {
        spin_angle += angular_velocity * Time.deltaTime;
        mesh_renderer.transform.localRotation =
            Quaternion.AngleAxis(MathUtility.RadiansToDegrees(spin_angle),
                                 new Vector3(0, 0, 1));

        Vector3 displacement = transform.position - last_position;

        RaycastHit[] raycast_hits = UnityEngine.Physics.RaycastAll(last_position, displacement.normalized, displacement.magnitude);

        foreach (RaycastHit raycast_hit in raycast_hits)
        {
            if (raycast_hit.collider.gameObject == Source.gameObject)
            {
                continue;
            }

            if (raycast_hit.collider.gameObject.HasComponent <Mortal>())
            {
                Mortal   mortal   = raycast_hit.collider.gameObject.GetComponent <Mortal>();
                Physical physical = mortal.GetComponent <Physical>();

                float angle = (mortal.transform.position - raycast_hit.point).AngleBetween(displacement);
                float intersection_length = Mathf.Min(mortal.transform.localScale.y / Mathf.Cos(angle),
                                                      raycast_hit.point.Distance(transform.position));

                float energy_imparted = Physical.KineticEnergy * (1 - Mathf.Pow(Penetration, intersection_length));
                Physical.KineticEnergy -= energy_imparted;

                float damage_energy = 0;
                if (physical == null)
                {
                    damage_energy = energy_imparted;
                }
                else if (Physical.Velocity.magnitude > mortal.ImpactTolerance)
                {
                    damage_energy = energy_imparted * mortal.ImpactFragility;
                }

                float kinetic_energy = energy_imparted - damage_energy;

                if (kinetic_energy > 0)
                {
                    physical.Velocity += Physical.Velocity.normalized *
                                         Measures.MetersToWorldUnits(Mathf.Sqrt(2 * kinetic_energy / physical.Mass));
                }

                mortal.Health.Value -= BaseDamage * KineticEnergyToDamage(damage_energy);
            }
        }

        if (Scene.Main.World.Asteroid.GetSurfaceHeight(Physical.Position) > transform.position.y)
        {
            GameObject.Destroy(gameObject);
        }
    }
Exemplo n.º 2
0
    public void UpdateCharacterLifeBar(Mortal _toUpdate)
    {
        Transform panelToUpdate = associatedCharacterPanel[_toUpdate.GetComponent <PawnInstance>()];
        Image     lifeBarImg    = panelToUpdate.GetChild((int)CharactersPanelChildren.LifeBar).GetChild((int)LifeBarChildren.Remaining).GetComponent <Image>();

        lifeBarImg.fillAmount = _toUpdate.CurrentHp / (float)_toUpdate.Data.MaxHp;
        lifeBarImg.sprite     = GameManager.Instance.SpriteUtils.spritePlayerGreenLifeBar;

        if (lifeBarImg.fillAmount < 0.33f)
        {
            lifeBarImg.color = Color.red;
        }
        else
        {
            lifeBarImg.color = Color.green;
        }
        panelToUpdate.GetChild((int)CharactersPanelChildren.LifeBar).GetChild((int)LifeBarChildren.Text).GetComponent <Text>().text = _toUpdate.CurrentHp + " / " + _toUpdate.Data.MaxHp;
    }