New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New physics based first/third person 3d and platformer like modular navigation + input axis and others #533
base: master
Are you sure you want to change the base?
Conversation
… ShouldDoDefaultMovement(). Change fly/walk in game code.
…layer's collider has friction player can't rotate.
…to fix all errors and make it much easier to use physics ray/sphere cast.
… ground using the new TCastleCollider.Middle(). Also removed Michalis TODO - will never be done in that class we work on new navigation system.
Poor GitHub will explode from our big pull requests :) Thank you! To everyone who reads this -- this a big, big new feature (actually a combination of a few things) that Andrzej has been working on for a while, and we've talked about a lot of details of this together. It's a set of behaviors that allow to easily set up a working navigation (for a wide range of games, as you can see in the description above -- 1st person 3D, 3rd person 3D, 2D like platformer...). It also adds TCastleAxis, a great new approach to monitor inputs in CGE. See the description above for details. If anyone wants to test it at this point -- go ahead. You can get from GitHub the branch https://github.com/castle-engine/castle-engine/tree/physics_third_person_navigation , and compile the CGE using https://castle-engine.io/compiling_from_source.php . Feedback is most appreciated. |
I forgot to add info about changes in our physics. Kraft has been updated and I also fixed one rare crash (BeRo1985/kraft#33). Our rigid body support now sphere casting ( Physics ray cast itself has also new parameter In colliders there is new function that return scaled bounding box of collider ( |
Also adds CollisionLayers to PhysicsRayCast, following code from #533 too.
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
TSimplestFpsPlayerMovement
andTSimpleFpsPlayerMovementWithRotation
intended 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:
JumpSpeed
HorizontalSpeed
ForwardInputAxis
SidewayInputAxis
InputJump
In this case Player (TCastleTransform) should have camera as his child:
For camera rotations we use
TRotateCamera
behavior .TSimplestFpsPlayerMovement
will 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.TSimpleFpsPlayerMovementWithRotation
This behavior is similar to
TSimplestFpsPlayerMovement
but horizontal rotation (x axis) is made by rotating rigid body (using newTRotateRigidBody
behavior.The properties are the same like in
TSimplestFpsPlayerMovement
:JumpSpeed
HorizontalSpeed
ForwardInputAxis
SidewayInputAxis
InputJump
In this case Player (TCastleTransform) should have camera as his child and be configured like that:
The only difference is using
TRotateRigidBody
for horizontal rotation (y axis) and now inTRotateCamera
we 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
TModularMovement
TModularMovement
TModularMovement
is 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
TModularMovement
and 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 alsoExists
property 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
TWalk3DSupport
for player moving if we want head bobbing simply addTHeadBobbing
for crouchTFpsCrouch
et cetera.How it works underneath?
TModularMovement
has only three functions:All modules inherit from
TAbstractMovementModule
and implements/overidesUpdateMovement()
function.Properties
ForwardInputAxis
SidewayInputAxis
InputJump
GroundPhysicsLayers
Configuration
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_shooter
example.TPP game:
Here we also use
TFollowingTargetForCamera
behavior in camera that supports following an object by 3d camera without writing any line of code.See
castle-engine/examples/physics/physics_3d_third_person
example.Platformer game
See examples/physics/physics_2d_movement
All modules list
TAnimationTrigger
TFpsCrouch
TFly3DSupport
TWalk3DSupport
THeadBobbing
TStairsSupportByColliderCapsuleRadius
TPlatformer2DWalkSupport
TPlatformer2DInAirControl
TDoubleJumpSupport
TInAir3DControl
Other behaviors
Behaviors that can be usable in many use cases:
TDirectRotateTransformByKeys
TFollowingTargetForCamera
Target
(like in TPP games)TRotateCamera
TRotateRigidBody
Input 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 updateMouseLookLastDelta
that can be used everywhere in your game. See TCastleInputAxis Value function andcastle-engine/examples/physics/physics_3d_shooter
main unit for exampleSimple way to use mouse drag
There are tow new functions in
TCastleContainer
:StartMouseDrag()
and StopMouseDrag(); AfterStartMouseLook()
Container starts updateMouseDragDelta
that can be used everywhere in your game. SeeTCastleInputAxis.Value()
function andcastle-engine/examples/physics/physics_3d_shooter
man unit for exampleSimple way to use mouse wheel everywhere
There is
LastUpdateMouseWheelDirection
inTCastleContainer
that contains mose wheel direction change from latest frameCached
Collider
andRigidBody
in 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