Javascript Mathf.Ceil understanding problems

I use following code for a damage calculation all with floats:

var Off_To_Def_Hits: float = Mathf.Ceil((OffForce - DefForce) / ((DefAgility * Defsize) / 2));

I used print to check the calculation. It say in this case:

print("DmgCalc.: " + "DmgDiff: " + ((OffForce - DefForce)) + ", / Dodging= " + ((DefAgility * Defsize) / 2) + " Raw.OffToDefHits: " + Off_To_Def_Hits);

Mathf.Ceil((117f - 48f) / 6f) = 5

75993-dmgcalcfail.jpg

But I expected 12! Wheres the problem??

you are getting everything correct in your log then i m damn sure that off_To_Def_Hits is getting its value from somewhere else before it is being used in Debug.Log and after it is assigned its value from your formula …

Or, show us your script pls

@aditya:
Here’s the complete script (wont fit in a comment). I’ve changed now DefAgility and Defsize to its direct origin, but it doesn’t help. Sorry for the german things, but scripts are all in english…

Offensive Fleet Stats I used:

@Header("Allianz: 1 = Brismarch-Bewegung, 2 = Eigerson-Opposition")
public var Alliance: int = 1;

@Header("1 = Kampf, 2 = Support, 3 = Handel")
public var Fleetrole: int = 1;

@Header("Anzahl Schiffe pro Flotte")
public var Fleetsize: float = 12.0;

@Header("Anzahl Sprünge pro Zug")
public var Velocity: int = 4;

@Header("Kapazität pro Schiffe in der Flotte")
public var Capacity: float = 50;

@Header("Reichweite der Sensoren")
public var Sensorrange: float = 2.0;

@Header("Manövrierbarkeit der Schiffe")
public var Agility: float = 4.0;

@Header("Offensivsysteme des Verbandes")
public var Offensivesystems: float = 2.0;

@Header("Defensivsysteme des Verbandes")
public var Defensivesystems: float = 2.0;

@Header("Rollenfähigkeit des Verbandes")
public var Roleability: Component;

Defensive Fleet Stats I used:

@Header("Allianz: 1 = Brismarch-Bewegung, 2 = Eigerson-Opposition")
public var Alliance: int = 2;

@Header("1 = Kampf, 2 = Support, 3 = Handel")
public var Fleetrole: int = 1;

@Header("Anzahl Schiffe pro Flotte")
public var Fleetsize: float = 6.0;

@Header("Anzahl Sprünge pro Zug")
public var Velocity: int = 2;

@Header("Kapazität pro Schiffe in der Flotte")
public var Capacity: float = 150.0;

@Header("Reichweite der Sensoren")
public var Sensorrange: float = 3.0;

@Header("Manövrierbarkeit der Schiffe")
public var Agility: float = 2.0;

@Header("Offensivsysteme des Verbandes")
public var Offensivesystems: float = 3.0;

@Header("Defensivsysteme des Verbandes")
public var Defensivesystems: float = 3.0;

@Header("Rollenfähigkeit des Verbandes")
public var Roleability: Component;

The calculationscript (for runtime testing, add 3 empties, add one script per empty, connect the fleetempties to the calculationscript, hit “Space”):

import System.Collections.Generic;

public var AttackingFleet: GameObject;
public var DefendingFleet: GameObject;

private var Round: int = 1;
private var AttackingShipCount: int;
private var DefendingShipCount: int;

function Update(){

    if(AttackingFleet != null && DefendingFleet != null && Input.GetKeyDown(KeyCode.Space)){ 
            Calculation();
    }

    if(Input.GetKeyDown(KeyCode.R)){ 
        Round = 1;
        AttackingShipCount = 0;
        DefendingShipCount = 0;
    }
    
}

function Reset(){ 
     
    AttackingFleet.gameObject.GetComponent(BasicFleet);
    DefendingFleet.gameObject.GetComponent(BasicFleet);

}

function Calculation(){
                   
    //Count all ships
    AttackingShipCount = AttackingFleet.gameObject.GetComponent(BasicFleet).Fleetsize;
    DefendingShipCount = DefendingFleet.gameObject.GetComponent(BasicFleet).Fleetsize;            

    //Show number of involved ships
    if(Round == 1){
        print("Ratio: " + AttackingShipCount + " / " + DefendingShipCount);
    }

    if((AttackingShipCount > 0 && DefendingShipCount > 0)){

        //Temporary fleet variables
        var OffensiveFleet: GameObject;
        var DefensiveFleet: GameObject;
                            
        //Find the fleet with the highest sensorrange value
        if(AttackingFleet.gameObject.GetComponent(BasicFleet).Sensorrange > DefendingFleet.gameObject.GetComponent(BasicFleet).Sensorrange || AttackingFleet.gameObject.GetComponent(BasicFleet).Sensorrange == DefendingFleet.gameObject.GetComponent(BasicFleet).Sensorrange){
            OffensiveFleet = AttackingFleet;
            DefensiveFleet = DefendingFleet;
        } else {
            OffensiveFleet = DefendingFleet;
            DefensiveFleet = AttackingFleet;
        }
        //Create quick fleetscript link for parameters
        var OffP = OffensiveFleet.gameObject.GetComponent(BasicFleet);
        var DefP = DefensiveFleet.gameObject.GetComponent(BasicFleet); 
        if(Round == 1){
            print("Höchste Sensorreichweite hat " + OffensiveFleet.name + " mit " + OffP.Sensorrange + "Mio. Kilometern");
        }
        //End        
            
        //Shows fighting round
        print("- - - - - - - - - - - - - - - - - - -");
        print("Runde: " + Round);

        //||||||||||||||||||||||||||||||||||

        //Attack from offensive forces
        var OffAttackPower: float;
        var n: float;
        for(n = OffP.Offensivesystems; n > 0; n--){ //Dice simulation
            OffAttackPower = OffAttackPower + Random.Range(1, 7);
        }
        var OffAttackForce: float = OffP.Fleetsize * ((OffAttackPower * OffP.Sensorrange) / 2); // * OffP.Sensorrange
        print(OffensiveFleet.name + " attackiert mit einer Stärke von " + OffAttackForce + " Punkten");
        print("AttCalc.: " + "Fleetsize: " + OffP.Fleetsize + ", (AttPwr * Sensr. / 2)= " + ((OffAttackPower * OffP.Sensorrange) / 2));

        //Defend from defensive forces
        var DefDefensePower: float;
        for(n = DefP.Defensivesystems; n > 0; n--){ //Dice simulation
            DefDefensePower = DefDefensePower + Random.Range(1, 7);
        }
        var DefDefenseForce: float = DefP.Fleetsize * ((DefDefensePower * DefP.Sensorrange) / 2); // * DefP.Sensorrange
        if(DefDefenseForce > OffAttackForce){
            DefDefenseForce = OffAttackForce; //Preventing from defending more attacks than possible
        }
        print(DefensiveFleet.name + " wehrt " + DefDefenseForce + " Angriffspunkte ab");
        print("DefCalc.: " + "Fleetsize: " + DefP.Fleetsize + ", (DefPwr * Sensr. / 2)= " + ((DefDefensePower * DefP.Sensorrange) / 2));

        //First damage calculation
        var RawOffToDefHits: float = Mathf.Ceil((OffAttackForce - DefDefenseForce) / ((DefP.Agility * DefP.Fleetsize) / 2));
        var OffToDefHits: int = Mathf.FloorToInt(RawOffToDefHits);
        if(OffToDefHits > DefP.Fleetsize){
            OffToDefHits = DefP.Fleetsize; //Preventing from hitting more ships than fleetsize
        }
        DefP.Fleetsize -= OffToDefHits;
        print("FleetLosing: " + OffToDefHits);
        print("DmgCalc.: " + "DmgDiff: " + ((OffAttackForce - DefDefenseForce)) + ", / Dodging= " + ((DefP.Agility * DefP.Fleetsize) / 2) + " Raw.OffToDefHits: " + RawOffToDefHits);

        print(Mathf.FloorToInt(OffToDefHits) + " Schiff(e) von " + DefensiveFleet.name + " zerstört oder bschädigt!");
        //Strike back
        if(DefP.Fleetsize > 0){

            //Attack from defensive forces
            var DefAttackPower: float;
            for(n = DefP.Offensivesystems; n > 0; n--){ //Dice simulation
                DefAttackPower = DefAttackPower + Random.Range(1, 7);
            }
            var DefAttackForce: float = DefP.Fleetsize * (DefAttackPower * DefP.Sensorrange);
            print(DefensiveFleet.name + " schlägt mit einer Stärke von " + DefAttackForce + " Punkten zurück");

            //Defend from offensive forces
            var OffDefensePower: float;
            for(n = OffP.Defensivesystems; n > 0; n--){ //Dice simulation
                OffDefensePower = OffDefensePower + Random.Range(1, 7);
            }
            var OffDefenseForce: float = OffP.Fleetsize * (OffDefensePower * OffP.Sensorrange);
            if(OffDefenseForce > DefAttackForce){
                OffDefenseForce = DefAttackForce; //Preventing from defending more attacks than possible
            }
            print(OffensiveFleet.name + " wehrt " + OffDefenseForce + " Angriffspunkte ab");

            //Second damage calculation
            var DefToOffHits: int = Mathf.CeilToInt((DefAttackForce - OffDefenseForce) / (OffP.Agility * OffP.Fleetsize));
            if(DefToOffHits > OffP.Fleetsize){
                DefToOffHits = OffP.Fleetsize; //Preventing from hitting more ships than fleetsize
            }
            OffP.Fleetsize -= DefToOffHits;        
            print(DefToOffHits + " Schiff(e) von " + OffensiveFleet.name + " zerstört oder bschädigt!");

            if(OffP.Fleetsize <= 0){
                if(OffP.Fleetsize < 0){
                    OffP.Fleetsize = 0;
                }
                if(Round == 1){
                    print(OffensiveFleet.name + " wurde vernichtend geschlagen!");
                } else print(OffensiveFleet.name + " wurde zerschlagen!");
            }

        } else {
            if(DefP.Fleetsize < 0){
                DefP.Fleetsize = 0;
            }
            if(Round == 1){
                print(DefensiveFleet.name + " wurde vernichtend geschlagen!");
            } else print(DefensiveFleet.name + " wurde zerschlagen!");        }

        Round++;

    } else {
        
        print("- - - - - - - - - - - - - - - - - - -");
        print("Die Schlacht ist entschieden!");

        AttackingFleet == null;
        DefendingFleet == null;

    }

}