Frictional Games | Forum | Newsletter | Dev Blog | Dev Wiki | Support | Shelf | Store

• 14 Votes - 2.93 Average
• 1
• 2
• 3
• 4
• 5
 Challenge Threadᆦ ᆦ ᆦ Author Message
nemesis567
Posting Freak

Posts: 840
Joined: May 2011
Reputation: 10
 Post: #161 RE: [CHALLENGE THREAD] Ok, I fixed that. It was really just changing the funciton that determines the state which is a pretty easy one anyway. Here is the solution: http://www.mediafire.com/?i2avy6vjiczuazg And here goes the explaining: PHP Code: (Select All) `const int MAX_BARRELS = 14;const int playerWeight = 40;float[] aBridge = {0, 0, 0};//USE VALUES BETWEEN 0 and 3.14/2(pi/2)!!!//Note that the weight varies from 0 to 90 in the briges. This happens because the sen(x) function varies between MAX and MINIMUM values between 90 and -90 degrees or Pi/2 and -pi/2 radians.void OnStart(){    AddAttachedPropToProp("bridge_1", "scriptCollider_Bridge_1", "bridgeCollider.ent", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); //Add the entity to detect if anything is ON the bridge.    AddAttachedPropToProp("bridge_2", "scriptCollider_Bridge_2", "bridgeCollider.ent", 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);     AddDebugMessage("Added Colliders",false);    for(int i = 1; i<=MAX_BARRELS; i++)//For each barrel add a collide callback    {        AddEntityCollideCallback("scriptCollider_Bridge_1", "barrel01_"+i, "OnEntityCollide", false, 0 );        AddEntityCollideCallback("scriptCollider_Bridge_2", "barrel01_"+i, "OnEntityCollide", false, 0 );    }    AddEntityCollideCallback("Player", "scriptCollider_Bridge_1", "OnEntityCollide", false, 0 ); //add collide callbacks for the player    AddEntityCollideCallback("Player", "scriptCollider_Bridge_2", "OnEntityCollide", false, 0 );    }void OnEntityCollide(string &in asParent, string &in asChild, int alState) {    if(asParent == "scriptCollider_Bridge_1")    {        float fWeight = getWeight(asChild); //Function getweight returns the weight of a preset object.        AddDebugMessage("Colided with bridge 1",false);        if(alState == 1)//If is entering the area/Is now on the bridge        {            aBridge[1] += fWeight;//Increase bridge 1's weight            aBridge[2] -= fWeight;//Bridge's 2 weight is reduced. This does not really happens. But since weight(force vector) + tension(assuming there is no friciton in the mechanism the tension equals the other bridges weight) equals a vector that equals: Bridge2weight-Bridge1weight. (without friction)        }        else if(alState == -1)//If is leaving the area/is now off the bridge        {            aBridge[1] -= fWeight; //Same, but now when an item exists the bridge.            aBridge[2] += fWeight;        }        updateBridges();            }    else if(asParent == "scriptCollider_Bridge_2") //Same as above.    {        float fWeight = getWeight(asChild);        AddDebugMessage("Colided with bridge 2",false);        if(alState == 1)        {            aBridge[2] += fWeight;            aBridge[1] -= fWeight;        }        else if(alState == -1)        {            aBridge[2] -= fWeight;            aBridge[1] += fWeight;        }        updateBridges();    }    else if(asParent == "Player")//Same as above    {        if(asChild == "scriptCollider_Bridge_1")        {            float fWeight = playerWeight;            AddDebugMessage("Colided with bridge 1",false);            if(alState == 1)            {                aBridge[1] += fWeight;                aBridge[2] -= fWeight;            }            else if(alState == -1)            {                aBridge[1] -= fWeight;                aBridge[2] += fWeight;            }            updateBridges();        }        else if(asChild == "scriptCollider_Bridge_2")//Same as above        {            float fWeight = playerWeight;            AddDebugMessage("Colided with bridge 2",false);            if(alState == 1)            {                aBridge[2] += fWeight;                aBridge[1] -= fWeight;            }            else if(alState == -1)            {                aBridge[2] -= fWeight;                aBridge[1] += fWeight;            }            updateBridges();            }    }}void updateBridges()//Will update each bridge state{    float state = calcState(degToRad(aBridge[1])); //calcState calculates a value between MAX elevation and Min Elevation of each bridge accordingly. degToRad converts te degrees to radians    float state2 = calcState(degToRad(aBridge[2]));//same    SetMoveObjectStateExt("bridge_1", state, 4.0, 4.0, 0.5, false);//Set's the bridge's elevation    SetMoveObjectStateExt("bridge_2", state2,4.0, 4.0, 0.5, false);}float calcState(float nVal){    float result = sin(nVal);//Useless. Used for debug.    if(nVal > 3.15/2) return 0.55;    else if(nVal < -3.13/2) return -0.55;    else return 0.55 * sin(nVal);}/*int calcDifference(float &out fDifference){    AddDebugMessage("fD", false);    if(aBridge[1] > aBridge[2]) return 1; //--Brigdge 1 has more weight than bridge 2    else if(aBridge[1] < aBridge[2]) return -1; // -Bridge 2 has more weight than bridge 1    else return 0; //Both have the same weight;}*/float getWeight(string sObjectName) //Would be usefull if you had boxes and other things to use other than barrels{    if(StringContains(sObjectName, "barrel")) return 20.0; //Barrel Weight. Random weight    return 0;}float degToRad(float degVal)//Conversion from degrees to radians.{    return degVal*(3.14/180);}// APPJM math thing, I'm not in the mood to do it//Begin Math - In here are the functions abs and sin. ` I assume this makes me the winner. Today I dreamt the life I could live forever. You only know that when you feel it for you know not what you like until you've experienced it. (This post was last modified: 04-29-2012 10:22 PM by nemesis567.)
04-29-2012 09:55 PM
 « Next Oldest | Next Newest »