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
Next revisionBoth sides next revision
dragengine:modules:dragonscript:locomotion [2017/02/22 15:16] – [Body tilting] dragonlorddragengine:modules:dragonscript:locomotion [2017/02/22 15:34] – [Body tilting] dragonlord
Line 153: Line 153:
  
 <code> <code>
-// set up locomotion body tilt for an actor using the weighted method +func void init() 
-locomotion.setTiltMode( Locomotion.TILT_WEIGHTED ) +  // set up locomotion body tilt for an actor using the weighted method 
- +  locomotion.setTiltMode( Locomotion.TILT_WEIGHTED ) 
-// create collision filter shared by all tests +   
-var LayerMask category = LayerMask.new() +  // create collision filter shared by all tests 
-category.setBit( GameState.CL_AI )      // we are an collider for doing actor ai +  var LayerMask category = LayerMask.new() 
- +  category.setBit( GameState.CL_AI )      // we are an collider for doing actor ai 
-var LayerMask filter = LayerMask.new() +   
-filter.setBit( GameState.CL_GEOMETRY )  // we can hit geometry like the ground +  var LayerMask filter = LayerMask.new() 
-filter.setBit( GameState.CL_AI )        // we can hit other actor ai colliders +  filter.setBit( GameState.CL_GEOMETRY )  // we can hit geometry like the ground 
- +  filter.setBit( GameState.CL_AI )        // we can hit other actor ai colliders 
-var CollisionFilter collisionFilter = CollisionFilter.new( category, filter ) +   
- +  var CollisionFilter collisionFilter = CollisionFilter.new( category, filter ) 
-// set collision test. the test points are located above the ground since otherwise tilting up can not +   
-// be detected. as a rule of thumb the test distance should be two times the start height. for each +  // set collision test. the test points are located above the ground since otherwise tilting up can not 
-// test a ray test is used. this is the fastest solution and works well for most situations. +  // be detected. as a rule of thumb the test distance should be two times the start height. for each 
-var float offset = 0.5                  // height above ground to start testing +  // test a ray test is used. this is the fastest solution and works well for most situations. 
-var Vector testDistance = Vector.new( 0.0, -offset * 2.0, 0.0 )          // distance to test downwards +  var float offset = 0.5                  // height above ground to start testing 
- +  var Vector testDistance = Vector.new( 0.0, -offset * 2.0, 0.0 )          // distance to test downwards 
-locomotion.setCCTTiltFrontLeft( ColliderCollisionTest.new( touchSensor, touchSensorShape,+   
- collisionFilter, Vector.new( -0.2, offset, 0.2 ), testDistance ) ) +  locomotion.setCCTTiltFrontLeft( ColliderCollisionTest.new( touchSensor, touchSensorShape,
- +    collisionFilter, Vector.new( -0.2, offset, 0.2 ), testDistance ) ) 
-locomotion.setCCTTiltFrontRight( ColliderCollisionTest.new( touchSensor, touchSensorShape,+  locomotion.setCCTTiltFrontRight( ColliderCollisionTest.new( touchSensor, touchSensorShape,
- collisionFilter, Vector.new( 0.2, offset, 0.2 ), testDistance ) ) +    collisionFilter, Vector.new( 0.2, offset, 0.2 ), testDistance ) ) 
- +  locomotion.setCCTTiltBackLeft( ColliderCollisionTest.new( touchSensor, touchSensorShape,
-locomotion.setCCTTiltBackLeft( ColliderCollisionTest.new( touchSensor, touchSensorShape,+    collisionFilter, Vector.new( -0.2, offset, -0.2 ), testDistance ) ) 
- collisionFilter, Vector.new( -0.2, offset, -0.2 ), testDistance ) ) +  locomotion.setCCTTiltBackRight( ColliderCollisionTest.new( touchSensor, touchSensorShape,
- +    collisionFilter, Vector.new( 0.2, offset, -0.2 ), testDistance ) ) 
-locomotion.setCCTTiltBackRight( ColliderCollisionTest.new( touchSensor, touchSensorShape,+   
- collisionFilter, Vector.new( 0.2, offset, -0.2 ), testDistance ) ) +  // add mappings so our animator uses the calculated values 
- +  locomotion.addControllerMaping( controllerTiltOffset, Locomotion.ATTR_TILT_OFFSET ) 
-// add mappings so our animator uses the calculated values +  locomotion.addControllerMaping( controllerTiltUpDown, Locomotion.ATTR_TILT_UP_DOWN ) 
-locomotion.addControllerMaping( controllerTiltOffset, Locomotion.ATTR_TILT_OFFSET ) +  locomotion.addControllerMaping( controllerTiltLeftRight, Locomotion.ATTR_TILT_RIGHT_LEFT ) 
-locomotion.addControllerMaping( controllerTiltUpDown, Locomotion.ATTR_TILT_UP_DOWN ) +end
-locomotion.addControllerMaping( controllerTiltLeftRight, Locomotion.ATTR_TILT_RIGHT_LEFT )+
  
 // tilt is enabled so during Element.postThink the tilt is updated automatically and the result // tilt is enabled so during Element.postThink the tilt is updated automatically and the result
 // applied to animator instance controllers // applied to animator instance controllers
-locomotion.updatePostLocomotion( elapsed )+func void postThink( float elapsedFrameTime ) 
 +  locomotion.updatePostLocomotion( elapsedFrameTime ) 
 +end
 </code> </code>
  
Line 202: Line 203:
 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 [[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.
  
 +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:
 +<code>
 +// create an input tracker and set parameters
 +func void init()
 +  tracker.setSpeedLookLeftRight( 45.0 ) // degrees per second
 +  tracker.setSpeedLookUpDown( 45.0 ) // degrees per second
 +  tracker.setSpeedTurnLeftRight( 30.0 ) // degrees per second. for vehicle type locomotion
 +  tracker.setCanTurn( true ) // player turning commands are used
 +  tracker.setCanMove( true ) // player movement commands are used
 +  tracker.setCanChangeStance( true ) // player stance change commands are used
 +  tracker.setSpeedWalk( 3.0 ) // meters per second. you can set backward speed individually
 +  tracker.setSpeedRun( 8.0 ) // meters per second. you can set backward speed individually
 +end
 +
 +// in reaction to player input commands alter state
 +func void playerPressForward()
 +  tracker.setMoveForward( true ) // button press (true), button release (false).
 +end
 +
 +func void playerMoveMouse( Point mouseMovement )
 +  // mouse movement during this frame update for natural and fps locomotion
 +  tracker.setAnalogLookLeftRight( mouseMovement.getX() )
 +  tracker.setAnalogLookUpDown mouseMovement.getY() )
 +end
 +
 +func void playerPressTurnVehicle()
 +  tracker.setTurnLeft( true ) // turning for vehicle type locomotion
 +end
 +
 +// then during each Element.think() call let the tracker update the locomotion
 +func void think( float elapsedFrameTime )
 +  tracker.updateLocomotion( locomotion, elapsedFrameTime )
 +end
 +</code>
dragengine/modules/dragonscript/locomotion.txt · Last modified: 2024/03/14 16:43 by dragonlord