New physics based first/third person 3d and platformer like modular navigation + input axis and others#533
New physics based first/third person 3d and platformer like modular navigation + input axis and others#533
Conversation
…TCastleContainer..
…k before destruction.
…DED_MANUAL comments
…ody.PhysicsSphereCast Adjusted from #533 , by Andrzej Kilijański
|
I've done some work to keep this up-to-date:
Overall, this is up-to-date again, and the diff between this and master got smaller :) |
…ame, document in README
…w lights setup Also remove old gameviewmain from physics_3d_shooter, leave only new ones that show new setup and _direct with old setup
|
I've done more fixes, to fix LPK and physics_3d_shooter lights. TODOs:
|
Because our current navigation system is quite difficult to modify. We were looking for a way to add navigation that would be, on the one hand, quick to add and, on the other hand, easy to modify. This can be achieved in two ways:
This PR adds two such possibilities. In all cases we assume that player transform has rigid body and collider.
In the case of the first approach, I implemented two behaviors
TSimplestFpsPlayerMovementandTSimpleFpsPlayerMovementWithRotationintended only for FPS games.TSimplestFpsPlayerMovement
This is the simplest one it assumes that rigid body has blocked rotations and movement direction is determined by the camera direction.
It has few properties:
JumpSpeedHorizontalSpeedForwardInputAxisSidewayInputAxisInputJumpIn this case Player (TCastleTransform) should have camera as his child:
For camera rotations we use
TRotateCamerabehavior .TSimplestFpsPlayerMovementwill only work well in the simplest of situations when we do not care about (invisible in FPS game) player rotation. And as I wrote it has only base functions (move and jump) and it is intended to be copied and modified by the game developer.TSimpleFpsPlayerMovementWithRotationThis behavior is similar to
TSimplestFpsPlayerMovementbut horizontal rotation (x axis) is made by rotating rigid body (using newTRotateRigidBodybehavior.The properties are the same like in
TSimplestFpsPlayerMovement:JumpSpeedHorizontalSpeedForwardInputAxisSidewayInputAxisInputJumpIn this case Player (TCastleTransform) should have camera as his child and be configured like that:
The only difference is using
TRotateRigidBodyfor horizontal rotation (y axis) and now inTRotateCamerawe rotate camera only vertical (x axis).But this behavior is also only a start point for game developer that wants do anything in his own way. But what if we don't want implement everything by ourself but still want modify it? We should use
TModularMovementTModularMovementTModularMovementis navigation system that can be used for all types of games like FPS, TPP and also 2D games.For most usecases, it is enough to use the modules that we have prepared, and if something is missing or should work differently, game programmer can create another module or modify the existing one.
How does it work?
At first we add
TModularMovementand then other modules depending on your needs e.g.For 2D platformer like game we add
TPlatformer2DWalkSupport- that covers jumping, moving left and right out of the box. When we want add double jump we just addTDoubleJumpSupport. All modules have alsoExistsproperty so when we want add double jump when player achieve something we simply set exists to false in editor and set to true in right moment.Similarly for an FPS game we will add
TWalk3DSupportfor player moving if we want head bobbing simply addTHeadBobbingfor crouchTFpsCrouchet cetera.How it works underneath?
TModularMovementhas only three functions:All modules inherit from
TAbstractMovementModuleand implements/overidesUpdateMovement()function.Properties
ForwardInputAxisSidewayInputAxisInputJumpGroundPhysicsLayersConfiguration
This all may seem complicated it is really easy and a lot of things can be achieved without coding any single line of code.
FPS game
See
castle-engine/examples/physics/physics_3d_shooterexample.TPP game:
Here we also use
TFollowingTargetForCamerabehavior in camera that supports following an object by 3d camera without writing any line of code.See
castle-engine/examples/physics/physics_3d_third_personexample.Platformer game
See examples/physics/physics_2d_movement
All modules list
TAnimationTriggerTFpsCrouchTFly3DSupportTWalk3DSupportTHeadBobbingTStairsSupportByColliderCapsuleRadiusTPlatformer2DWalkSupportTPlatformer2DInAirControlTDoubleJumpSupportTInAir3DControlOther behaviors
Behaviors that can be usable in many use cases:
TDirectRotateTransformByKeysTFollowingTargetForCameraTarget(like in TPP games)TRotateCameraTRotateRigidBodyInput Axis
I implemented simple Input Axis that observes some keys/mouse and returns a value. More info in docs. How to use check other behaviors. (this PR description is getting to long)
Simple way to use mouse look
There are tow new functions in
TCastleContainer:StartMouseLook()and StopMouseLook(); AfterStartMouseLook()Container starts updateMouseLookLastDeltathat can be used everywhere in your game. See TCastleInputAxis Value function andcastle-engine/examples/physics/physics_3d_shootermain unit for exampleSimple way to use mouse drag
There are tow new functions in
TCastleContainer:StartMouseDrag()and StopMouseDrag(); AfterStartMouseLook()Container starts updateMouseDragDeltathat can be used everywhere in your game. SeeTCastleInputAxis.Value()function andcastle-engine/examples/physics/physics_3d_shooterman unit for exampleSimple way to use mouse wheel everywhere
There is
LastUpdateMouseWheelDirectioninTCastleContainerthat contains mose wheel direction change from latest frameCached
ColliderandRigidBodyin TCastleTransformNow you don't need call FindBehavior every frame just get it by using cached pointers from TCastleTransform.
Some screenshots
Platformer game without writing any code:
TPP example:
FPS game:
More tips for TModularMovement