User Tools

Site Tools


hpl2:tutorials:script:running_up_walls

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl2:tutorials:script:running_up_walls [2013/08/25 18:59]
amn
hpl2:tutorials:script:running_up_walls [2015/07/17 20:32] (current)
amn
Line 1: Line 1:
 ====== Running up walls ====== ====== Running up walls ======
  
 +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.
  
-( Writing right now… )+1. How it works
  
 +{{http://​s21.postimg.org/​cjfsgmqqv/​running_up_walls_image_1.jpg?​direct&​}}
  
-This code will simulate ​the player ​running up walls.\\  +This feature uses areas to determine where the wall is and to detect when the player ​jumps to it.\\ 
-Since code ends up being too large and thus confusing, ​i'm dividing it in parts.+Using the function //​AddPlayerBodyForce// ​can simulate the force of each leg running up.
  
 +To get the interval between steps, i'm using //​Timers//​.\\
 +\\
 +We declare the area collision: ​ (//​AreaWall1 // is the area covering the wall and //​WallRunCollide // is the function.)
 +<code php>
 +void OnStart {
 + AddEntityCollideCallback( "​Player",​ "​AreaWall1",​ "​WallRunCollide",​ false, 1  );
 +}
 +</​code>​
  
-1. How it works+And this is the function that triggers when the players collides with the area:
  
 +<code php>
 +void WallRunCollide ( string &in p, string &in c, int s ) {
 + AddPlayerBodyForce( 0, 20000, 0, false );
 +}
 +</​code>​
  
-This feature uses areas to determine where the wall is and to detect when the player jumps to it.\\  +2Adjusting code +//Timer// +//Loop//
-Using the function ​//AddPlayerBodyForce// i can simulate the force of each leg running up.+
  
 +//BodyForce // function uses large numbers, so i'm using a variable instead:
 +<code php>
 +void WallRunCollide ( string &in p, string &in c, int s ) {
 + float M = 10000;
 + AddPlayerBodyForce( 0, 2*M, 0, false );
 +}
 +</​code>​
  
-To get the interval between steps, i'​m ​using //Timers//.\\  +This will push the player up just onceso i'​m ​adding a //Timer+Loop ​// to repeat ​the impulse ​(5 times):
-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.)+
 <code php> <code php>
-void OnStart ​{  +void WallRunCollide ( string &in p, string &in c, int s ) 
- AddEntityCollideCallback( "Player", ​"​AreaWall1"​, "WallRunCollide", false, 0 );+ float i = 0.25; int n = 5; float r = 0; 
 + 
 + for ( int v = 1; v <= n; v++ ) { 
 + AddTimer ​( "", ​r, "RunOnMe" ); 
 + r = r +i; 
 + }
 } }
 </​code>​ </​code>​
  
 +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:
 +<code php>
 +void RunOnMe ( string &in t ) {
 + float M = 10000;
 + AddPlayerBodyForce( 0, 2*M, 0, false );
 +}
 +</​code>​
  
-And this is the function that triggers when the players collides with the area:+This is supposed to be a step, i'm adding a sound:
  
 +<code php>
 +void RunOnMe ( string &in t ) {
 + float M = 10000;
 + AddPlayerBodyForce( 0, 2*M, 0, false );
 + PlayGuiSound( "​step_run_female_rock.snt",​ 0.4 );
 +}
 +</​code>​
 +
 +At this point, the code is working fine. You can test it out.
 +
 +3. Preventions
  
 +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 //​GetPlayerYSpeed()//​ function, anything below 1 is not jumping:
 <code php> <code php>
 void WallRunCollide ( string &in p, string &in c, int s ) { void WallRunCollide ( string &in p, string &in c, int s ) {
- AddPlayerBodyForce( 0, 20000, ​0, false );+ 
 + if GetPlayerYSpeed() <1 ) { return; } 
 + float i = 0.25; int n = 5; float r = 0
 + 
 + for ( int v = 1; v <= n; v++ ) { 
 + AddTimer ( ""​r, "​RunOnMe" ​); 
 + r = r +i; 
 + }
 } }
 +
 </​code>​ </​code>​
  
 +That new condition i just added will stop the code by using the //return // function.\\
 +So player may walk into the wall area and not get thrown up by the wall running code.
 +
 +4. Direction
 +
 +We are adding now a small tweak to our code to let the player direct his wall running.\\
 +Using //​AddPlayerBodyForce // we can add a slight push ahead: ( just to help the player go where he's looking at)
 +<code php>
 +void RunOnMe ( string &in t ) {
 + float M = 10000;
 + AddPlayerBodyForce( 0, 2*M, 0, false );
 + AddPlayerBodyForce( 0, 0, 0.7*M, true );
 + PlayGuiSound( "​step_run_female_rock.snt",​ 0.4 );
 +}
 +
 +</​code>​
 +
 +0.7<​nowiki>​*</​nowiki>​ M should be enough, remember this will run on every step. There'​s 5.
 +
 +5. Functionality
 +
 +This is the end of this guide. With this code you can experiment new functionalities and expand its possibilities.\\
 +If you're interested, you can take a look at my code in any script file from my mod Riukka for more developed functions on wall running.
  
-\\  +\\ 
-asd+Amn.-
  
hpl2/tutorials/script/running_up_walls.1377457180.txt.gz · Last modified: 2013/08/25 18:59 by amn