User Tools

Site Tools


scripting:basics

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
scripting:basics [2022/08/11 13:52] jerryhopperscripting:basics [2022/08/11 14:32] (current) jerryhopper
Line 15: Line 15:
 Notice the variable name 'btr' and the entityname 'BTR1' - You have to change these variables to reflect your entity ingame. Notice the variable name 'btr' and the entityname 'BTR1' - You have to change these variables to reflect your entity ingame.
  
-==== Example 1 ====+==== Example 1 a vehicle ====
    
 Get the entity of a vehicle with the name 'BTR1' Get the entity of a vehicle with the name 'BTR1'
Line 24: Line 24:
 **Lets break down this line.** **Lets break down this line.**
  
-This is where we declare our variablename and type, where the name is 'btr' and the type is 'GenericEntity' +This is where we declare our variablename and type, where the name is 'btr' and the type is 'GenericEntity' 
 +In Enfusion, variables has to be declared of which type they should be. Its fairly self-explanatory if you look at the line below. 
  
   GenericEntity btr =    GenericEntity btr = 
Line 44: Line 45:
  
  
-So, the result of the above is that we have a variable with the name 'btr' which 'type' is 'GenericEntity'+So, the result of the above is that we have a variable with the name '**btr**' which '**type**' is '**GenericEntity**'
  
  
  
  
-===== Get a CharacterEntity, and control it ====+==== Example 2: a Character ==== 
 + 
 +Lets try this with a soldier (character).  
 + 
 +So, we get the entity of a soldier with the name 'soldier_scripted' 
 + 
 +  GenericEntity soldier = GenericEntity.Cast(GetWorld().FindEntityByName("soldier_scripted")); 
 +   
 +Now we have the 'GenericEntity' in the variable 'soldier' To control this soldier, we need a controller component. Because we know the entity is in fact a 'character' - we need to get the characterController. 
 +This procedure is almost the same as you would get any other entity. 
 + 
 +  CharacterControllerComponent soldier_c = CharacterControllerComponent.Cast(soldier.FindComponent(CharacterControllerComponent)); 
 + 
 + 
 +So here we have a variable with the name 'soldier_c'  ( this is a descriptive variable, we know its a soldier and by appending the '_c' we know this is the soldier controller component) which contains the CharacterControllerComponent for our specific entity. 
 + 
 + 
 + 
 +---- 
 + 
 + 
 +===== Control a CharacterEntity ===== 
 + 
 + 
 +Lets continu from Example #2.  We now have an entity, and its time we control it
 + 
 +==== Change stance ==== 
 + 
 + 
 +If we want to change the stance of the soldier, we can do so via this CharacterController. 
 + 
 +  soldier_c.SetStanceChange(ECharacterStanceChange.STANCECHANGE_TOCROUCH); 
 + 
 +That looks quite straightforward, aside from the variable passed to the function. The stances of the character are defined in [[scripting:ECharacterStanceChange.c]], but i will list them below. 
 + 
 +  * STANCECHANGE_NONE, 
 +  * STANCECHANGE_TOERECTED, 
 +  * STANCECHANGE_TOCROUCH, 
 +  * STANCECHANGE_TOPRONE 
 + 
 + 
 +Notice that these are 'STANCE CHANGES' - not the actual stances (which are defined in [[scripting:echaracterstance.c]]).  
 + 
 +Great!  You are now able to control a soldier's stance by script! 
 + 
 +==== Move ==== 
 + 
 +Now lets try make the character move. To move a character, we need to know what speed and direction you want to move. We will use a variable which we declare as a '[[scripting:datatypes#vector]]' as shown below. 
 + 
 + 
 +  vector direction = {0,0,1}; 
 + 
 +The 'soldier_c' variable contains the CharacterController, and like with the stances, you can control the movement. Below you see the 'SetMovement' command to which we pass 'speed' (2) and the variable 'direction'
 + 
 +  soldier_c.SetMovement(2, direction); 
 +   
 +That should do the trick. Your character should be moving in the given direction.
scripting/basics.1660222331.txt.gz · Last modified: 2022/08/11 13:52 by jerryhopper

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki