User Tools

Site Tools


dragengine:modules:dragonscript:locomotion

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
dragengine:modules:dragonscript:locomotion [2019/05/08 17:30] dragonlorddragengine:modules:dragonscript:locomotion [2024/03/14 16:43] (current) dragonlord
Line 5: Line 5:
  
 ====== Locomotion ====== ====== Locomotion ======
-Locomotion defines the movement, looking, turnging and stance states of actors. The DragonScript module provides basic locomotion implementation using the [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Locomotion.html|locomotion class]]. Three kinds of locomotion types are well supported and can be extended according to needs. For performance reasons the locomotion class is implemented as native class. It is possible to extend the behavior but requires extending the class in a specific way to work. Whenever the player or an AI routine creates input new goals are set in the locomotion. The locomotion class then updates the actual values. Internal this uses [[gamedev:smoothvalue|smooth values]] to smoothly apply changes over time. The resulting parameters can then be used to update colliders for collision testing and animator instances for calculating animation states.+Locomotion defines the movement, looking, turnging and stance states of actors. The DragonScript module provides basic locomotion implementation using the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1Locomotion.html,locomotion class~@#. Three kinds of locomotion types are well supported and can be extended according to needs. For performance reasons the locomotion class is implemented as native class. It is possible to extend the behavior but requires extending the class in a specific way to work. Whenever the player or an AI routine creates input new goals are set in the locomotion. The locomotion class then updates the actual values. Internal this uses [[gamedev:smoothvalue|smooth values]] to smoothly apply changes over time. The resulting parameters can then be used to update colliders for collision testing and animator instances for calculating animation states.
  
 ====== Parameters ====== ====== Parameters ======
Line 90: Line 90:
 |Turn left-right|Turning is used here to turn the body into the direction the actor is moving. Set value to Look left-right.Goal. Optionally you can set the value to 0 if the player presses no movement keys to stop the body moving.| |Turn left-right|Turning is used here to turn the body into the direction the actor is moving. Set value to Look left-right.Goal. Optionally you can set the value to 0 if the player presses no movement keys to stop the body moving.|
  
-FPS locomotion is somewhat simpler to understand and is somewhat cheaper to calculate. There are two ways to handle the animation. The first solution is to use the same setup as in the natural locomotion case. Most of the time though an 8-way animation setup is used. In this case 8 animations of walking/running are created each representing the same movement but in a different direction relative to the camera direction. 8 animations are typically chosen this this way each animation is 45 degrees rotate compared to the next animation working well with digital input from 4 direction keys (north, north-west, west, south-west, south, south-east, east, norh-east). This setup requires more animation work to be done but has the advantage that all kinds of moving directions can be blended together with good quality. As a side note this setup could be also used for the naturla locomotion case but it is a bit delicate to get working in a pleasant way. This setup can be easily build using the [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ARGroup.html|group animator rule]] using the select mode. There the 8 animations can be added as 8 rules in the group and selecting being driven by the moving orientation.+FPS locomotion is somewhat simpler to understand and is somewhat cheaper to calculate. There are two ways to handle the animation. The first solution is to use the same setup as in the natural locomotion case. Most of the time though an 8-way animation setup is used. In this case 8 animations of walking/running are created each representing the same movement but in a different direction relative to the camera direction. 8 animations are typically chosen this this way each animation is 45 degrees rotate compared to the next animation working well with digital input from 4 direction keys (north, north-west, west, south-west, south, south-east, east, norh-east). This setup requires more animation work to be done but has the advantage that all kinds of moving directions can be blended together with good quality. As a side note this setup could be also used for the naturla locomotion case but it is a bit delicate to get working in a pleasant way. This setup can be easily build using the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ARGroup.html,group animator rule~@# using the select mode. There the 8 animations can be added as 8 rules in the group and selecting being driven by the moving orientation.
  
 ====== Vehicle Locomotion ====== ====== Vehicle Locomotion ======
Line 112: Line 112:
 Vehicle locomotion is the simplest locomotion type of the three and the cheapest. Disabling the turning adjustments and in-place turning is important to avoid the vehicle suddenly turning when the looking around approaches the border. Vehicle locomotion is the simplest locomotion type of the three and the cheapest. Disabling the turning adjustments and in-place turning is important to avoid the vehicle suddenly turning when the looking around approaches the border.
 ====== Animator and collider control ====== ====== Animator and collider control ======
-Locomotion allows to set an [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1AnimatorInstance.html|animator instance]] and mapping controllers. If set the locomotion updates the animator instance controllers with the appropriate locomotion values automatically upon updating. This is a convenience behavior of the locomotion class to improve performance since all this work is repetitive and can be done faster in C++ than inside scripts. The locomotion class documentation contains a list of supported controller mapping constants. The example below shows a typical setup.+Locomotion allows to set an #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1AnimatorInstance.html,animator instance~@# and mapping controllers. If set the locomotion updates the animator instance controllers with the appropriate locomotion values automatically upon updating. This is a convenience behavior of the locomotion class to improve performance since all this work is repetitive and can be done faster in C++ than inside scripts. The locomotion class documentation contains a list of supported controller mapping constants. The example below shows a typical setup.
  
 <code> <code>
Line 149: Line 149:
 <WRAP centeralign>Weighted body tile testing locations.</WRAP> <WRAP centeralign>Weighted body tile testing locations.</WRAP>
 </WRAP> </WRAP>
-Body tilting provides support to adjust animations of actors to better fit them to uneven ground. Body tilting require [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1ColliderCollisionTest.html|collider collision tests]] to determine the distances required to calculate proper tilting. The testing is done after the physics simulation step. For this reason locomotion calculation has to be split into a part before physics simulation (during Element.think) and a part after physics simulation (during Element.postThink). Locomotion can be set to do no body tilt calculation, single or weighted. In **single mode** one collision test is used usually straight under the actor. The hit normal on the ground is used to calculate the tilting on a virtual plane located under the actor with the hit normal matching the plane normal. This is fast and for many situations reasonable solution. In **weighted mode** 4 collision tests are used each of them located near feet like if the actor is quadripedal (if not really the case). The image below shows the layout.+Body tilting provides support to adjust animations of actors to better fit them to uneven ground. Body tilting require #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1ColliderCollisionTest.html,collider collision tests~@# to determine the distances required to calculate proper tilting. The testing is done after the physics simulation step. For this reason locomotion calculation has to be split into a part before physics simulation (during Element.think) and a part after physics simulation (during Element.postThink). Locomotion can be set to do no body tilt calculation, single or weighted. In **single mode** one collision test is used usually straight under the actor. The hit normal on the ground is used to calculate the tilting on a virtual plane located under the actor with the hit normal matching the plane normal. This is fast and for many situations reasonable solution. In **weighted mode** 4 collision tests are used each of them located near feet like if the actor is quadripedal (if not really the case). The image below shows the layout.
  
 The results are weighted to get a best matching virtual ground plane. This mode is most expensive but the results are more stable and of higher quality. Once done the tilt result can be applied to animator instance controlls as any other locomotion state. The results are weighted to get a best matching virtual ground plane. This mode is most expensive but the results are more stable and of higher quality. Once done the tilt result can be applied to animator instance controlls as any other locomotion state.
Line 197: Line 197:
  
 ====== State control and frame update ====== ====== State control and frame update ======
-To update the locomomotion multiple calls are used. After the player has provided input the [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Locomotion.html#ac5190fabffbd9da821ab224e142d2766|updateLooking()]] method can be used to smooth the input and to update the goal values used by the locomotion calculation step. Once the input is updated the locomotion can be calculated using [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Locomotion.html#a74bdb2d85b3a3b2b92898011d8a1c2f4|updateLocomotion()]] method. This calculates all the needed locomotion states using native code. This call is used during Element.think(). After the physics simulation is done the [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Scenery_1_1Locomotion.html#a86f426d718f0a534c745258bdc99e533|updatePostLocomotion]] method can be called to calculate body tilting and potential other calculations requiring physics test results. Afterward the animation instance has to be updated if not assigned to be done by the locomotion instance directly.+To update the locomomotion multiple calls are used. After the player has provided input the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1Locomotion.html#ac5190fabffbd9da821ab224e142d2766,updateLooking()~@# method can be used to smooth the input and to update the goal values used by the locomotion calculation step. Once the input is updated the locomotion can be calculated using #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1Locomotion.html#a74bdb2d85b3a3b2b92898011d8a1c2f4,updateLocomotion()~@# method. This calculates all the needed locomotion states using native code. This call is used during Element.think(). After the physics simulation is done the #@LinkApiDocDEDS2_HTML~classDragengine_1_1Scenery_1_1Locomotion.html#a86f426d718f0a534c745258bdc99e533,updatePostLocomotion~@# method can be called to calculate body tilting and potential other calculations requiring physics test results. Afterward the animation instance has to be updated if not assigned to be done by the locomotion instance directly.
  
 If you want to enhance the locomotion class you have to be careful about the calling structure. The native classes methods call themselves internally for performance reasons. The entire late binding is skipped. Overwriting the update calls has no effect in this case. To partially change behavior you have to implement the updateLocomotion() and updatePostLocomotion() calls yourself and call the native methods from the script. This allows to inject your changes in the right place. This all works since it is no problem to call a method from script if it is a native class but the native class. If you want to enhance the locomotion class you have to be careful about the calling structure. The native classes methods call themselves internally for performance reasons. The entire late binding is skipped. Overwriting the update calls has no effect in this case. To partially change behavior you have to implement the updateLocomotion() and updatePostLocomotion() calls yourself and call the native methods from the script. This allows to inject your changes in the right place. This all works since it is no problem to call a method from script if it is a native class but the native class.
  
 ====== Player Input Tracker ====== ====== Player Input Tracker ======
-To help with managing the player input for use with locomotions the DragonScript module provides a helper class [[http://dragengine.rptd.ch/docs/dragonscript/scriptapi/latest/classDragengine_1_1Utils_1_1PlayerInputTracker.html|PlayerInputTracker]]. This class is not mandatory but reduces implementation needs. The player input tracks what inputs the player has provided so far and calculates the goal locomotion changes my smoothing the changes over time using [[gamedev:smoothvalue|smooth values]]. Tracks digital input (pressing buttons like forward or strafing) as well as analog input (mouse, joystick axes). Call updateLocomotion() to smooth the input values and setting the appropriate goal values in a locomotion instance.+To help with managing the player input for use with locomotions the DragonScript module provides a helper class #@LinkApiDocDEDS2_HTML~classDragengine_1_1Utils_1_1PlayerInputTracker.html,PlayerInputTracker~@#. This class is not mandatory but reduces implementation needs. The player input tracks what inputs the player has provided so far and calculates the goal locomotion changes my smoothing the changes over time using [[gamedev:smoothvalue|smooth values]]. Tracks digital input (pressing buttons like forward or strafing) as well as analog input (mouse, joystick axes). Call updateLocomotion() to smooth the input values and setting the appropriate goal values in a locomotion instance.
  
 The //Player Input Tracker// supports all three mentioned locomotion types and has similar //Switches// like the locomotion class to disable individual calculations. The most simple use is like this: The //Player Input Tracker// supports all three mentioned locomotion types and has similar //Switches// like the locomotion class to disable individual calculations. The most simple use is like this:
dragengine/modules/dragonscript/locomotion.1557336630.txt.gz · Last modified: 2019/05/08 17:30 by dragonlord