コード例 #1
0
 public void HurtByActor(GameObject other, float damageToThis, float damageToOther, CollisionVelocityResults cvr)
 {
     CurrentState.HurtBy(other, damageToOther, damageToThis, cvr);
 }
コード例 #2
0
    void ActorCollision(int index)
    {
        StateMachine st = ColManager.Actors[index];

        //At least one must have a certain minimum momentum and both must be hurtable.
        if (CurrentState.Hurtable && st.CurrentState.Hurtable &&
            (Velocity.magnitude >= ActorProps.MinimumCollisionVelocity ||
             st.Velocity.magnitude >= st.ActorProps.MinimumCollisionVelocity))
        {
            float damageToThis, damageToOther;

            //Damage is primarily based on momentum.
            damageToThis  = st.Velocity.magnitude * st.ActorProps.Mass;
            damageToOther = Velocity.magnitude * ActorProps.Mass;

            //The actor on top has an advantage which grows as it approaches being directly above.

            float maxColDist = ActorBounds.extents.y + st.ActorBounds.extents.y;

            if (transform.position.y > st.transform.position.y)
            {
                damageToOther *= Mathf.Max(1.0f, ActorProps.MaxAdvantageMultiplier *
                                           Mathf.Abs(transform.position.y - st.transform.position.y) / maxColDist);
            }

            else if (transform.position.y < st.transform.position.y)
            {
                damageToThis *= Mathf.Max(1.0f, st.ActorProps.MaxAdvantageMultiplier *
                                          Mathf.Abs(st.transform.position.y - transform.position.y) / maxColDist);
            }

            //If the two actors are from the same team, scale down their damage.
            if (ActorData.Team.Equals(st.ActorData.Team))
            {
                damageToThis  *= st.ActorProps.SameTeamMultiplier;
                damageToOther *= ActorProps.SameTeamMultiplier;
            }

            //Figure out which actor won the collision and notify both actors..
            CollisionVelocityResults v = new CollisionVelocityResults();
            if (damageToThis >= damageToOther)
            {
                damageToOther *= ActorProps.LostCollisionMultiplier;
                v              = NewVs(st, this);

                HurtByActor(st.gameObject, damageToThis, damageToOther, v);
                st.HurtActor(gameObject, damageToOther, damageToThis, v);

                WorldConstants.Creator.CreatePlayerHurtParticles(this);
            }
            else
            {
                damageToThis *= st.ActorProps.LostCollisionMultiplier;
                v             = NewVs(this, st);

                HurtActor(st.gameObject, damageToThis, damageToOther, v);
                st.HurtByActor(gameObject, damageToOther, damageToThis, v);

                WorldConstants.Creator.CreatePlayerHurtParticles(st);
            }

            //Update pain calculations.
            UpdatePainStats(st, damageToThis, damageToOther);
            st.UpdatePainStats(this, damageToOther, damageToThis);
        }
    }