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 19:31]
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.\\
-( 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. Since code ends up being too large and thus confusing, i'm dividing it in parts.
- 
  
 1. How it works 1. How it works
  
 +{{http://​s21.postimg.org/​cjfsgmqqv/​running_up_walls_image_1.jpg?​direct&​}}
  
-This feature uses areas to determine where the wall is and to detect when the player jumps to it.\\ +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. Using the function //​AddPlayerBodyForce//​ i can simulate the force of each leg running up.
  
- +To get the interval between steps, i'm using //​Timers//​.\\ 
-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.) We declare the area collision: ​ (//​AreaWall1 // is the area covering the wall and //​WallRunCollide // is the function.)
 <code php> <code php>
-void OnStart {  +void OnStart { 
- AddEntityCollideCallback( "​Player",​ "​AreaWall1",​ "​WallRunCollide",​ false, ​);+ AddEntityCollideCallback( "​Player",​ "​AreaWall1",​ "​WallRunCollide",​ false, ​1  ​);
 } }
 </​code>​ </​code>​
- 
  
 And this is the function that triggers when the players collides with the area: And this is the function that triggers when the players collides with the area:
- 
  
 <code php> <code php>
Line 35: Line 28:
 </​code>​ </​code>​
  
- +2. Adjusting code +//Timer// +//Loop//
-2. Adjusting code +
  
 //BodyForce // function uses large numbers, so i'm using a variable instead: //BodyForce // function uses large numbers, so i'm using a variable instead:
-<code php>void WallRunCollide ( string &in p, string &in c, int s ) {+<code php> 
 +void WallRunCollide ( string &in p, string &in c, int s ) {
  float M = 10000;  float M = 10000;
- AddPlayerBodyForce( 0, 2*M, 0, false );+ AddPlayerBodyForce( 0, 2*M, 0, false );
 } }
 </​code>​ </​code>​
  
- +This will push the player up just once, so i'm adding a //​Timer+Loop // to repeat the impulse (5 times):
-This will push the player up just once, so i'm adding a //​Timer+Loop//​to repeat the impulse (5 times): +
- +
 <code php> <code php>
 void WallRunCollide ( string &in p, string &in c, int s ) { void WallRunCollide ( string &in p, string &in c, int s ) {
  float i = 0.25; int n = 5; float r = 0;  float i = 0.25; int n = 5; float r = 0;
- 
  
  for ( int v = 1; v <= n; v++ ) {  for ( int v = 1; v <= n; v++ ) {
Line 62: Line 50:
 </​code>​ </​code>​
  
- +As you can see, the content changed, i moved it to another new function.\\ 
-As you can see, the content changed, i moved it to another new function.\\  +I added 3 variables, interval, number and a counter.\\ 
-I added 3 variables, interval, number and a counter.\\  +These are used in the //for loop.\\ 
-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.//​\\ 
-// 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: Below is the new function i created that the //Timers// will trigger:
-<code php>void RunOnMe ( string &in t ) {+<code php> 
 +void RunOnMe ( string &in t ) {
  float M = 10000;  float M = 10000;
  AddPlayerBodyForce( 0, 2*M, 0, false );  AddPlayerBodyForce( 0, 2*M, 0, false );
 } }
 </​code>​ </​code>​
- 
  
 This is supposed to be a step, i'm adding a sound: 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>​
  
-<code php>void RunOnMe ( string &in t ) {+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> 
 +void WallRunCollide ( string &in p, string &in c, int s ) { 
 + 
 + 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>​ 
 + 
 +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;  float M = 10000;
  AddPlayerBodyForce( 0, 2*M, 0, false );  AddPlayerBodyForce( 0, 2*M, 0, false );
 + AddPlayerBodyForce( 0, 0, 0.7*M, true );
  PlayGuiSound( "​step_run_female_rock.snt",​ 0.4 );  PlayGuiSound( "​step_run_female_rock.snt",​ 0.4 );
 } }
 +
 </​code>​ </​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.1377459094.txt.gz · Last modified: 2013/08/25 19:31 by amn