Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 14 Vote(s) - 2.93 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge Threadᆦ ᆦ ᆦ
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
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 = {000};//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.00.00.00.00.00.0); //Add the entity to detect if anything is ON the bridge.
    
AddAttachedPropToProp("bridge_2""scriptCollider_Bridge_2""bridgeCollider.ent"0.00.00.00.00.00.0); 
    
AddDebugMessage("Added Colliders",false);
    for(
int i 1i<=MAX_BARRELSi++)//For each barrel add a collide callback
    
{
        
AddEntityCollideCallback("scriptCollider_Bridge_1""barrel01_"+i"OnEntityCollide"false);
        
AddEntityCollideCallback("scriptCollider_Bridge_2""barrel01_"+i"OnEntityCollide"false);
    }
    
AddEntityCollideCallback("Player""scriptCollider_Bridge_1""OnEntityCollide"false); //add collide callbacks for the player
    
AddEntityCollideCallback("Player""scriptCollider_Bridge_2""OnEntityCollide"false);
    
}


void OnEntityCollide(string &in asParentstring &in asChildint 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"state4.04.00.5false);//Set's the bridge's elevation
    
SetMoveObjectStateExt("bridge_2"state2,4.04.00.5false);
}

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
Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
RE: [CHALLENGE THREAD]

I've actually confirmed that the MoveAxis amount is the size of the model in the level editor (after scaling, so a 2x2x2 meter box that is scaled to 3 on each side would move 6 meters, not 2), and the "set open amount" just sets how many of these MoveAxis amounts is considered "open."

As for the speed of the bridges, even if it is fine for the sake of the challenge it still bugs me, as I see no reason why they would move up and down at different speeds. Sad

04-30-2012, 05:22 AM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
RE: [CHALLENGE THREAD]

(04-30-2012, 05:22 AM)Homicide13 Wrote: I've actually confirmed that the MoveAxis amount is the size of the model in the level editor (after scaling, so a 2x2x2 meter box that is scaled to 3 on each side would move 6 meters, not 2), and the "set open amount" just sets how many of these MoveAxis amounts is considered "open."

As for the speed of the bridges, even if it is fine for the sake of the challenge it still bugs me, as I see no reason why they would move up and down at different speeds. Sad
You should finish your solution anyway. Before Apjjm releases it.

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-30-2012, 12:54 PM by nemesis567.)
04-30-2012, 12:54 PM
Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
RE: [CHALLENGE THREAD]

(04-30-2012, 12:54 PM)nemesis567 Wrote: You should finish your solution anyway. Before Apjjm releases it.
I mean it's technically already finished, that one problem just really bugged me.

http://www.mediafire.com/download.php?15t21svj043abdc

This module can be used to implement a balancing system between any two vertical move objects, provided that they are named [commonName]_1 and [commonName]_2, and that there is an entity used to detect collisions that can be placed directly in the same place as the entities in the balance system named [commonName]Collider.ent

In order to set up the relationship between the two objects, the user only needs to declare 3 lines of script. One to declare the object, one to initialize the system, and one more line because I couldn't figure out how to get collide callbacks to call a function within a class. The user can have as many balance objects as he likes in his script, provided he follow each of these steps for each of them.

And that's that.

(This post was last modified: 04-30-2012, 01:39 PM by Homicide13.)
04-30-2012, 01:38 PM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
RE: [CHALLENGE THREAD]

Ok. Since you're the only participant left, this closes the challenge. About the collide callback within the class. I also found that a problem until Apjjm gave me the idea of having a global array that would store the created objects, so you could later in the script find what class object corresponds to a certain entity.

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.
04-30-2012, 02:02 PM
Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
RE: [CHALLENGE THREAD]

(04-30-2012, 02:02 PM)nemesis567 Wrote: Ok. Since you're the only participant left, this closes the challenge. About the collide callback within the class. I also found that a problem until Apjjm gave me the idea of having a global array that would store the created objects, so you could later in the script find what class object corresponds to a certain entity.
How do you mean?


04-30-2012, 03:04 PM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
RE: [CHALLENGE THREAD]

I haven't seen your code. But suppose you have the class Object1

PHP Code: (Select All)
Object1[] myArray;

class 
Object1
{
    
    
Object1();//Constructor - Not done here - Adds the created object to the array.
    
addCollideObject(string ); //Adds collide callback between an object(function parameter), sName and calls function OnCollide
    
string getName() const
    {
        return 
sName;
    }
    
    private 
string sName;
    

}


void OnCollide...
{
    for(
int i 0myArray.lenght(); ++i)
    {
       if(
myArray[i]->getName() == asParent)
       {
             
myArray[i]->myClassFunction();
        }
    }




That will not work but it represents what I meant.

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-30-2012, 05:27 PM by nemesis567.)
04-30-2012, 05:26 PM
Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
RE: [CHALLENGE THREAD]

Ah that's cool.
But won't defining values of an array cause a buffer overflow if you don't define the max size of the array first (or if you pass that max size)? Or does Angelscript automatically increase the size of the array?

05-01-2012, 12:48 AM
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
RE: [CHALLENGE THREAD]

No, you'll have to use array.resize();

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.
05-01-2012, 01:12 AM
Find
Homicide13 Offline
Senior Member

Posts: 323
Threads: 41
Joined: Nov 2010
Reputation: 14
RE: [CHALLENGE THREAD]

Hm Wait a second, why are you using the "->" to reference the class' member functions? Isn't this only used with pointer variables (which the array in your example isn't)? Or does Angelscript automatically just overload this to "." (though I don't really see why it would do this)?

(This post was last modified: 05-01-2012, 05:24 AM by Homicide13.)
05-01-2012, 05:20 AM
Find




Users browsing this thread: 1 Guest(s)