User Tools

Site Tools


hpl2:tutorials:script:disable_gravity_tutorial

Link to this comparison view

Both sides previous revision Previous revision
hpl2:tutorials:script:disable_gravity_tutorial [2011/01/11 16:28]
frontcannon [The scripting]
hpl2:tutorials:script:disable_gravity_tutorial [2011/02/15 21:17] (current)
l1ght5h0w
Line 1: Line 1:
-====== Beginner Scripting Tutorial 1======+====== Beginner Scripting Tutorial 1 ======
  
-//This is an easy tutorial for beginners. It is not intended to teach you new techniques but more to show you all the neat stuff you can do with the functions and the HPL2 engine.// 
  
-In this tutorial you'​ll ​learn how to make entities '​float'​ or rather make them seem to be very very light. +//This is an easy tutorial for beginners. It is not intended to teach you new techniques but more to show you all the neat stuff you can do with the functions and the HPL2 engine.//  
-Possible uses could be for some strange sanity effects or even simulating an underwater environment!+ 
 + 
 +In this tutorial you will learn how to make entities '​float'​ or rather make them seem to be very very light. Possible uses could be for some strange sanity effects or even simulating an underwater environment! 
  
 ===== Getting started ===== ===== Getting started =====
-Start by creating a new level in the level editor and then saving the map. There are no real limits, but keep it simple and include some movable entities you can use the script on. In my little room it'​s ​the skull and two books. You should include another entity you don'​t ​use the effect on, so you can compare their characteristics!+ 
 + 
 +Start by creating a new level in the level editor and then saving the map. There are no real limits, but keep it simple and include some movable entities you can use the script on. In my little room they are the skull and two books. You should include another entity you do not use the effect on, so you can compare their characteristics! 
  
 My room looks like this: My room looks like this:
  
-[[http://​imgur.com/​OiFEr.png|Link]] 
  
-After you have saved your map, create a .hps file with the same name. This is where we'​ll ​do all the scripting, add the default script there. I have removed the if-clause in my example, it'​s ​not needed.+[[http://​imgur.com/​OiFEr.png|Link]]  
 + 
 + 
 +After you have saved your map, create a .hps file with the same name. This is where we will do all the scripting, add the default script there. I have removed the if-clause in my example, it is not needed. 
  
 <code c>////////////////////////////​ <code c>////////////////////////////​
Line 21: Line 29:
    ​GiveItemFromFile("​lantern",​ "​lantern.ent"​);​    ​GiveItemFromFile("​lantern",​ "​lantern.ent"​);​
    
-   ​for(int i=0;​i<​10;​i++) GiveItemFromFile("​tinderbox_"​+i,​ "​tinderbox.ent"​); ​   ​+   ​for(int i=0;i< 10;i++) GiveItemFromFile("​tinderbox_"​+i,​ "​tinderbox.ent"​); ​   ​
 } }
    
Line 38: Line 46:
 } }
 </​code>​ </​code>​
 +
  
 ===== The scripting ===== ===== The scripting =====
  
  
-Now we'​ll ​do the actual scripting! The floating effect is based on timer functions, and one of these we'​ll ​add in //​OnStart()//​ so it is immediately called when the level loads! The syntax for timer function looks like this:+Now we will do the actual scripting! The floating effect is based on timer functions, and one of these we will add in //​OnStart()//​ so it is immediately called when the level loads! The syntax for timer function looks like this:
  
  
Line 68: Line 77:
  
  
-For actually making the objects float, we'​ll ​add this function in **FloatObjects**:​+For actually making the objects float, we will add this function in **FloatObjects**:​
  
  
Line 89: Line 98:
  
  
-So now I'​ve ​added an impulse for every object I want to float (the skull and the two books) and a timer that calls itself, repeating **FloatObjects** over and over.+So now I have added an impulse for every object I want to float (the skull and the two books) and a timer that calls itself, repeating **FloatObjects** over and over.
  
  
-You may have noticed that I'​ve ​only put in a value for the //afY// float. That means the impulse only goes in the Y direction or UP! 0.15 is a very weak impulse, but it is applied every 0.01 seconds so all the little pushes ​can'​t ​be noticed by the player which creates the effect of the objects floating or falling very slowly. You can now save the .hps file and load your level. Have fun and thanks for reading!+You may have noticed that I have only put in a value for the //afY// float. That means the impulse only goes in the Y direction or UP! 0.15 is a very weak impulse, but it is applied every 0.01 seconds so all the little pushes ​ca not be noticed by the player which creates the effect of the objects floating or falling very slowly. You can now save the .hps file and load your level. Have fun and thanks for reading! 
  
 ===== Additional information ===== ===== Additional information =====
-Here you can put the little things you've noticed while playing around and testing my script. Stuff I've already found out: 
  
-  ​* Different entities need different //afY// values! For small objects like books 0.15 is enough, but everything bigger than 2 will make them float upwards like a helium balloon. + 
-  * Play around with //afTime//! Bigger values like 0.5 combined with larger impulses like 5 can create some crazy bouncing effect!+Here you can put the little things you have noticed while playing around and testing my script. Stuff I have already found out: 
 + 
 + 
 +    ​* Different entities need different //​afY// ​ values! For small objects like books 0.15 is enough, but everything bigger than 2 will make them float upwards like a helium balloon. 
 + 
 + 
 +    ​* Play around with //afTime//! Bigger values like 0.5 combined with larger impulses like 5 can create some crazy bouncing effect!
  
hpl2/tutorials/script/disable_gravity_tutorial.txt · Last modified: 2011/02/15 21:17 by l1ght5h0w