Esempio n. 1
0
    //This function will detect character collision and calculate damage
    //Return 1: keep the projectile going
    //Return 0: this object shouldn't be impacted
    //Return -1: this projectile is stopped by character
    public int impact_character(Body_hitbox_generic hit_box, Vector2 hit_point)
    {
        Body_generic body = hit_box.body;

        if (body.gameObject == activator)
        {
            return(-1);
        }
        if (local)
        {
            float heat_dmg = 0;
            float angle    = Mathf.Atan2(aimdir.y, aimdir.x) * 180 / Mathf.PI;
            if (activator.GetComponent <Body_generic>().dmg_tags.Contains(body.tag))
            {
                heat_dmg = Damage();
            }
            Vector2 force = CONSTANTS.DAMAGE_FORCE_MULTIPLIER * aimdir.normalized * heat_dmg / 20;

            //If Client authoritates laser
            if (activator.GetComponent <Body_generic>().isPlayer&& !activator.GetComponent <Body_generic>().isServer)
            {
                activator.GetComponent <Player_controller>().add_to_shot_list(body.gameObject, heat_dmg, hit_point, force.magnitude, CONSTANTS.seed_float_to_short(angle, 360), false, 1);
                body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
            }
            else//Server client || npc authoritates laser
            {
                if (heat_dmg > 0)
                {
                    body.damage(activator, force, dmg_physics: CONSTANTS.heat_to_physics(heat_dmg), dmg_thermal: heat_dmg, headshot: false);
                    if (body.isPlayer && !body.hasAuthority)//Non-server client
                    {
                        body.request_bleed(hit_point, angle, false);
                        body.Rpc_add_force(force);
                    }
                    else//Host or npc
                    {
                        body.request_bleed(hit_point, angle, false);
                        body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
                    }
                }
                //Friendly fire, just force
                else
                {
                    if (body.isPlayer && !body.hasAuthority)//Non-server client
                    {
                        body.Rpc_add_force(force);
                    }
                    else//Host or npc
                    {
                        body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
                    }
                }
            }
        }
        return(-1);
    }
Esempio n. 2
0
    //This function will detect character collision and calculate damage
    //Return 1: keep the projectile going
    //Return 0: this object shouldn't be impacted
    //Return -1: this projectile is stopped by character
    public int impact_character(Body_hitbox_generic hit_box, Vector2 hit_point)
    {
        Vector2      force = CONSTANTS.DAMAGE_FORCE_MULTIPLIER * aimdir * speed * mass / 2;
        Body_generic body  = hit_box.body;

        if (body.isPlayer && !body.hasAuthority)//client player
        {
            body.Rpc_add_force(force);
        }
        else//host player & npc
        {
            body.GetComponent <Rigidbody2D>().AddForceAtPosition(force, hit_point);
        }
        if (activator.GetComponent <Body_generic>().dmg_tags.Contains(hit_box.tag))
        {
            body.damage(activator, force: force, dmg_physics: Damage(), headshot: false);
        }
        return(-1);
    }