( Writing right now… )
This code will simulate the player running up walls.
Since code ends up being too large and thus confusing, i'm dividing it in parts.
1. How it works
This feature uses areas to determine where the wall is and to detect when the player jumps to it.
Using the function AddPlayerBodyForce i can simulate the force of each leg running up.
To get the interval between steps, i'm using Timers.
This is how the code looks like now:
We declare the area collision: (AreaWall1 is the area covering the wall and WallRunCollide is the function.)
void OnStart { AddEntityCollideCallback( "Player", "AreaWall1", "WallRunCollide", false, 0 ); }
And this is the function that triggers when the players collides with the area:
void WallRunCollide ( string &in p, string &in c, int s ) { AddPlayerBodyForce( 0, 20000, 0, false ); }
2. Adjusting code
BodyForce function uses large numbers, so i'm using a variable instead:
void WallRunCollide ( string &in p, string &in c, int s ) { float M = 10000; AddPlayerBodyForce( 0, 2*M, 0, false ); }
This will push the player up just once, so i'm adding a Timer+Loop to repeat the impulse (5 times):
void WallRunCollide ( string &in p, string &in c, int s ) { float i = 0.25; int n = 5; float r = 0; for ( int v = 1; v <= n; v++ ) { AddTimer ( "", r, "RunOnMe" ); r = r +i; } }
As you can see, the content changed, i moved it to another new function.
I added 3 variables, interval, number and a counter.
These are used in the for loop.
This loop will set a Timer to call the function “RunOnMe” n times, on an interval of i seconds.
Below is the new function i created that the Timers will trigger:
void RunOnMe ( string &in t ) { float M = 10000; AddPlayerBodyForce( 0, 2*M, 0, false ); }
This is supposed to be a step, i'm adding a sound:
void RunOnMe ( string &in t ) { float M = 10000; AddPlayerBodyForce( 0, 2*M, 0, false ); PlayGuiSound( "step_run_female_rock.snt", 0.4 ); }
At this point, the code is working fine. You can test it out.
Now we have to consider possible bugs.
We don't want to trigger this if the player didn't jump.
It would look weird and just fail cause there's not enough starting force.
We can avoid that using
v
continues…