SiliconStudio / xenko

Old repo for Xenko Game Engine. Please use https://github.com/xenko3d/xenko instead.
http://xenko.com
1.54k stars 345 forks source link

[Physics] Allow CharacterController to behave like KinematicBody #60

Closed ArtiomCiumac closed 9 years ago

ArtiomCiumac commented 9 years ago

As title says, it would be nice to have this feature, as currently CharacterController behaves like StaticRigidBody which doesn't allow realistic physics interactions - for example if I want my character to push some objects.

sinkingsugar commented 9 years ago

Actually the charactercontroller is kinematic, if it was static would not move at all. Stuff like moving and pushing objects is really something that the game development team should implement, it is quite easy actually, as you just need to listen to the collision events directly from the CharacterController and handle that event as needed from the game.

Or totally re-implement a controller from a RigidBody. but then again that is something that must be decided in game design. The API offers all the tools to make them working.

Edit: I will add some samples about this topic! thanks for the feedback.

ArtiomCiumac commented 9 years ago

In the current implementation CharacterController is definitely not kinematic - try to move it with keyboard to hit some physics objects - the collisions doesn't result in a realistic reaction. It behaves more like a StaticRigidBody - the physics engine processes the collisions correctly, but doesn't take in consideration it's movement speed to translate inertia to objects it collides with.

While this can be useful when exact character control is needed, it is not useable for realistic interactions with other objects.

Looking in source code, I am not sure if you can do there anything, as the implementation comes from BulletPhysics. Well, I guess I will stick with my own implementation using a KinematicRigidBody.

I think you can either close this issue or leave it as low priority - as to fully resolve it requires a custom character controller implementation.

sinkingsugar commented 9 years ago

The thing is that CharacterController is not a RigidBody. And generally in games this is exactly what you want, because the game designers should be able to tweak the interactions between character and world.

You could use a KinermaticRigidbody to describe a character, but then this could result to weird interactions as it uses a more generic way. But if it fits your needs that is perfectly fine. You could even use a DynamicRigidBody.

If you are curious you could check btKinematicCharacterController in the bullet source, this is what CharacterController comes from.

Also, generally in physics engines "static" is used for entities that will never move, and so they are not even in the processing pipeline. "kinematic" is more about the fact that the game code will control the entity movement while in the "dynamic" case generally the physics engine is the authority for movement and transformations. In the case of rigidbodies, interaction with other rigidbodies is implemented implicitly. But note that KinematicRigidBody will not interact with static and other kinematic bodies.