User Tools

Site Tools


hpl2:tutorials:script:running_up_walls

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
hpl2:tutorials:script:running_up_walls [2013/08/25 21:56]
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.\\
-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&​}} {{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//​.\\  +\\
-\\ +
 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, 1  );  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 +//Timer// +//​Loop// ​ +
  
 //BodyForce // function uses large numbers, so i'm using a variable instead: //BodyForce // function uses large numbers, so i'm using a variable instead:
Line 46: Line 37:
 } }
 </​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):
Line 52: Line 42:
 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++ ) {
  AddTimer ( "",​ r, "​RunOnMe"​ );  AddTimer ( "",​ r, "​RunOnMe"​ );
Line 61: 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> <code php>
Line 75: Line 63:
 } }
 </​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> <code php>
Line 87: Line 73:
 } }
 </​code>​ </​code>​
- 
  
 At this point, the code is working fine. You can test it out. At this point, the code is working fine. You can test it out.
- 
  
 3. Preventions 3. Preventions
  
- +Now we have to consider possible bugs.\\ 
-Now we have to consider possible bugs.\\  +We don't want to trigger this if the player didn't jump.\\ 
-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.\\
-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: 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 ) {
-  + 
-  + if ( GetPlayerYSpeed() <1 ) { return; }
- if ( GetPlayerYSpeed() <1 ) { return; }  +
  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++ ) {
  AddTimer ( "",​ r, "​RunOnMe"​ );  AddTimer ( "",​ r, "​RunOnMe"​ );
Line 112: Line 93:
  }  }
 } }
- +
 </​code>​ </​code>​
  
- +That new condition i just added will stop the code by using the //return // function.\\
-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. So player may walk into the wall area and not get thrown up by the wall running code.
- 
  
 4. Direction 4. Direction
  
- +We are adding now a small tweak to our code to let the player direct his wall running.\\
-We are adding now a small tweak to our code to let me 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) Using //​AddPlayerBodyForce // we can add a slight push ahead: ( just to help the player go where he's looking at)
 <code php> <code php>
 void RunOnMe ( string &in t ) { 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 );  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. 0.7<​nowiki>​*</​nowiki>​ M should be enough, remember this will run on every step. There'​s 5.
- 
  
 5. Functionality 5. Functionality
  
- +This is the end of this guide. With this code you can experiment new functionalities and expand its possibilities.\\
-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. 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.
  
- +\\
-\\ +
 Amn.- Amn.-
  
hpl2/tutorials/script/running_up_walls.txt · Last modified: 2015/07/17 20:32 by amn