#rigidbody3d player controller ?

1 messages · Page 1 of 1 (latest)

elfin tangle
#

Except all I could see on the Godot doc, is there any detailed physics equations resources linked to the native Godot Physics engine or the Jolt physics engine ? I am a beginner in game development with a background of engineer and PhD associate professor on finite element analysis and others mechanics, physics : so I aim to build a player controller based upon physics but I haven't find the good web link... If somebody could help, and show an example of such a { RigidBody3D / or Jolt } player controller, thanks in advance!

young hull
elfin tangle
# young hull Here's the one from the official demo projects <https://github.com/godotengine/...

Thanks a lot for your response. It gives indeed some explanations with _physics_process(), but I have read (I forgot where) that the best method consists in using the _integrate_forces() method. Except one focus in the godot doc I didn't find some example of player controller with such a process. Perhaps I choose the bad way? In fact, as a beginner I would like to full understand the coding physics behind. I aim to model more realistic physics scene with mainly low poly geometries.

young hull
# elfin tangle Thanks a lot for your response. It gives indeed some explanations with _physics_...

The physics engine will use the applied forces/impulses/torque to calculate linear and angular velocity and then change the Rigidbodies position and rotation according to them.

If you make direct changes to the latter ones it will interfere with what the physics engine does and lead to weird glitches.

In _integrate_forces() you are able to overwrite those velocities and Transform properties safely.

However, usually you want to stick to forces, impulses and torque to control your Rigidbodies so the physics engine is able to simulate them fully and apply all other external forces, gravity, damping, joint constraints etc to give you a "realistic" result

elfin tangle
# young hull The physics engine will use the applied forces/impulses/torque to calculate line...

Thanks again, you seem to be very aware and accurate on these topics! If I understand, for the physics engine linked to physics_process (always with RigidBody3D) : apply force/impulse/torque yield to movement (through velocities), but for the integrate_forces() method how does it work (with detailed equations) ? Finally, what's your advice between integrate_forces() or physics_process() for player controller ? Such a question seems to me fundamental as it is the real gameplay. I have not still understood the advantages/drawbacks between these two processes for a player controller (in RigidBody3D) as I didn't find an example of player controller with integrate_forces().

young hull
# elfin tangle Thanks again, you seem to be very aware and accurate on these topics! If I under...

_integrate_forces() is usually only used to handle some specific cases that can't be done in _physics_process(). It doesn't replace _physics_process().

An example would be teleporting the Rigidbody to another position. If you were to change the position of a Rigidbody directly outside _integrate_forces() the physics engine would overrule that change and put it back to where it was previously.

In practice that would look like

func _integrate_forces(state):
  state.transform.origin= teleport_position

It's possible however to use a custom_integrator ( Rigidbody property ), which means all built-in physics will be disabled and then you could write your own physics implementation in _integrate_forces(). But this is very rare. I've never done it, I don't know of any examples and I can't really think of a use case either.

elfin tangle
# young hull _integrate_forces() is usually only used to handle some specific cases that can'...

Ok, thanks. So when you wrote "It doesn't replace _physics_process()" what do you mean ? Godot lets use both _physics_process() and integrate_forces() or only one can be used in a game?

In fact I work on finite element modelling in my job, and also I know some physics, mechanics, thermal, elasticity. But of course it consumes a lot of resources for simulation and in a video game the objective consists in obtaining the efficiency. Thus, we have to get inspired from real physics and choose the best model.
Of course I have no pretensions to start a model from scratch, the developers and experts have already done it. I would like to full understand the choices and processes in order to be able to build another things.

For instance, as I followed courses on the web, I understood that CharacterBody3D doesn't allow some physics, and in a game I imagine, I would like to model some situation :
the player is for example a detective in a town, he is pursued by a mafioso and the player runs and crosses a road with many cars, each car has its own mass, acceleration, velocity and both the player and the enemy too.
Following the velocity of both player and enemy, I would like to implement first the real contact (if so) between the car and the character impacted. According to the impact, damages are calculated and the bounce is calculated by the physics engine. Then, the character is dead or injured which impact his velocity after. So any advices?

That's why I would like to full understand the physics behind _process_physics() and _integrate_forces() with examples, as perhaps in my case the _process_physics() allows such a model? But you, as expert, wrote that you don't know any examples, perhaps one can contact the developers for more explanations?

young hull
# elfin tangle Ok, thanks. So when you wrote "It doesn't replace _physics_process()" what do yo...

I try to put it in other words: you don't have to choose between _physics_process() and _integrate_forces(). They can be used together.
But _integrate_forces() will be used rarely, you should try to work with _physics_process() as much as possible. When you run into a problem where the default physics engine behavior isn't what you want you can override in _integrate_forces().
But you wouldn't necessarily know these limitations until you have more experience working with the engine.

In your example everything can be achieved in _physics_process(): The movement of your Rigidbody character, the cars driving physics, etc.
The realistic collision response between him and the Rigidbody cars is automatic, taking all the built-in properties like mass etc into account, using the physics material to determine the bounce factor.
You can retrieve the contact impulse and use it to simulate damage.

I like this channel because I think it gives you the best overview of all the different physics nodes, although it's older and you will find some properties in different places in the current version. The name KinematicBody was changed to CharacterBody.
In your example you probably want to use Rigidbodies for everything that's moving to get a truly interactive simulation.

https://youtu.be/D-nOjV-mniE?feature=shared

Looking into the base class for all the physics bodies and area nodes, the CollisionObject. If you have any feedback, be it topic suggestions, criticism, or advice for future content please let me know down in the comment section.

00:00 - Intro

Collision Masks/Layers
00:23 - Collision Layer/Mask Explanation.
01:03 - Misleading Nature of the La...

▶ Play video
elfin tangle
elfin tangle
# young hull I try to put it in other words: you don't have to choose between _physics_proces...

The step further, I would like to investigate is : in my previous example, if two cars impact, it would be nice to have a kind of deformation taken into account. As in elasticity with Hooke's law, the deformation are so low that bodies return to natural state, but with plasticity some deformation remain. So, I think over it, with the simplest way to do it => in order to see some deformation of the crashed cars (realistics but always with low poly design for minimizing resources). It means that cars should be built with a few control points or an assembly of a few shapes ? If you know about it....interesting and already done ? Thank you for your attention to this subject.

young hull
# elfin tangle The step further, I would like to investigate is : in my previous example, if tw...

This is a very complex topic and in most cases only handled visually. I think there are many approaches but I don't know anything about that.

In older games you could see that they had premade damage models/textures to replace the original one.
But I guess you could do it dynamically by deforming the mesh.

There will be a lot to find with google on this topic in general and also some godot specific forum posts.
Maybe if you dig really deep you could find a demo project on github or even an addon.

elfin tangle
# young hull This is a very complex topic and in most cases only handled visually. I think th...

Ok, indeed I imagine deform the mesh, or perhaps even with an assembly of rigid bodies to form a whole body, is it possible ? As I consider low poly structure... But, you are right, I must keep on searching with google this topic (I already searched for fast mass spring system, it is linked to animation like Dreamworks etc). If I find something relevant can I share here ? In fact I am also a beginner on discord so I acknowledge that I am not familiar with all rules. Thanks again for your time.

young hull
#

There are 2 ways that I can think of if you want to simulate physical deformation:

  • The easiest way would be to have multiple collision shapes as children of your cars rigidbody and alter or remove the specific ones where the impact occurs
  • a complicated but more realistic one could be an approach where you have multiple Rigidbodies and connect them via joints ( it's the only way to connect Rigidbodies, any other approach would interfere with the physics simulation ).
    Some joint types support settings similar to spring forces where you could, in theory, set it up so that certain parts of a car can be pushed inwards as result of an impact. I think I read somewhere that Beam.NG uses a mechanic like that.
    But you'll be limited to the properties these joints are providing and simulating elasticity and plasticity in this way might even be impossible. My guess is there's an 80% chance that it's possible to make it work with the stuff that's available to us, but there's no guarantee. And you have to become an expert at working with the physics engine as well, with very limited resources available to learn from and probably also very little support.

There are only a handful of people who have a very good understanding of the physics engine, even the official developers don't have a "physics guy" and need to rely on 3rd party software ( Jolt ) and external volunteer maintainers.

By the way: it's fine if you share a link to something here you came across on the internet, as long as it isn't a virus download 😉

elfin tangle
#

Ok thanks, the easiest way is interesting but also the rigidbodies connected by joints : I must lean how to control these joints physically I mean to take into account forces and limits (as kinematically I think the engine works). I hope that when the problem is well identified a work of few months would enable to work. I share now what I found yesterday with google on these topics. The "deformable-mesh" link appears interesting ? https://github.com/cloudofoz/godot-deformablemesh

But I must full understand how make a link between physics and the mesh, it is possible I think with script :

  • identify a collider area and knowing :
    -> the kinematic properties of both bodies in impact,
    -> mass, elasticity linked to stiffness,
    -> coding a limit of elasticity that switch to plasticity i.e. deformed stated
    The question is how link a shape morphology of this addon with the shapes of both bodies. It is very interesting to take into account the stiffness/elasticity of each for accessing to damage/plasticity.

I found also some other links that I still haven't watched in details, what do you think ?

https://forum.godotengine.org/t/how-would-i-make-a-car-in-godot-deform-similar-to-a-real-car/58203/3

https://documentation.beamng.com/modding/vehicle/intro_jbeam/

https://www.reddit.com/r/godot/comments/1it1cp3/a_shader_for_car_crashes/

https://www.reddit.com/r/godot/comments/1iiutad/characterbody3d_collision_how_to_approach_using/

GitHub

Addon to deform 3D meshes using customizable deformers at run-time. - cloudofoz/godot-deformablemesh

Reddit

Explore this post and more from the godot community

Reddit

Explore this post and more from the godot community

young hull
# elfin tangle Ok thanks, the easiest way is interesting but also the rigidbodies connected by ...

The approach BeamNG takes is extremely interesting. If you want to go for realism I think that would be your best bet.
I think this is also the only solution that is guaranteed to work as expected and absolutely doable in Godot.

But it's also probably the most complex one. This would probably have to be completely written yourself, from what I've heard Godots Softbody3D are nowhere near ready for this.

There's a pretty good tutorial for how this can be coded in 2D:
https://youtu.be/3OmkehAJoyo?feature=shared

In this video I visually explain all of the elements involved in creating a (2D) soft-body physics simulation like the one I created for the JellyCar series.

JellyCar Worlds is now available on Steam, Nintendo Switch, and iOS!
More details at: https://jellycargame.com

0:00 Intro
0:36 Points
1:07 Shapes
1:30 Collision Detection
6:20 Springs
8:3...

▶ Play video
elfin tangle
young hull
elfin tangle
# young hull As far as I know this has to be done from scratch. The functionality of the Soft...

Ok, that's exactly what I wanted to check, because I thought that this kind of models were already implemented, and there is always no point in spending time redoing those that others have already done.

But if I have to start from scratch,
(1) can I do it under godot?
(2) Or do I have to program everything in C++ for example?
(3) Or finally, is it possible to use Jolt's routines and insert the physical parts related to mass / plasticity etc?
(4) Does Unity or UE5 implement what I aim to do ?

I realize these questions are rather vague, but in case you have the answer! Thanks again!

young hull
# elfin tangle Ok, that's exactly what I wanted to check, because I thought that this kind of m...
  1. Yes

  2. Can be done in GDScript, for a high number of those collision point nodes C++ might be faster if the calculations get too complex but it's impossible to say if it's like a 1% or 30% performance increase without having it already implemented

  3. I don't know enough about how to implement this custom solution in detail, I can't say how much of the built-in physics engine you will be using or if it will all be coded from scratch. This is a little too complex for my brain to wrap around fully, I tried to predict in my head what will be needed but couldn't come to any answer.

  4. Their physics engines should work very similar internally to ours, so generally my answer would be no. However, they may have a plugin that does some of this stuff already

elfin tangle
# young hull 1. Yes 2. Can be done in GDScript, for a high number of those collision point n...

Thanks again for your analysis. I think over it i.e. doign from scratch, I imagine a code where I could implement elasticity, plasticity and also crack/fracture?.... So do you have any advice for crack/fracture propagation ? Furthermore, is it possible to change the nature of objects during the game? That is to say that the player's environment would be transformed into a meshdef, for possible interactions, and as soon as the player moves away from this area, then the environment becomes a static mesh (to save resources), and so on?

young hull
elfin tangle
# young hull I think the technique from BeamNG should be able to support cracks and fractures...

Thanks, I explored some other links : SPH (Smooth Particle Hydrodynamics) , MIS (Mass Interaction System), perydynamic and others, the industry of computing graphics linked to research areas, in order to have a more global view. I have downloaded also some game physics books, and more I learn, more I see the link with research I practice! But also, I wonder now which model I will choose for start working with practical aspects. It seems to me that good last articles and thesis were up to 2020. But I acknowledge that I am not yet comfortable in coding so that I am still uncertain to make the best choice of physics algorithm, as the real time calculations is the first priority. So, if you have any advice... This subject is more tricky than expected.

young hull
# elfin tangle Thanks, I explored some other links : SPH (Smooth Particle Hydrodynamics) , MIS ...

I think the recency of the articles doesn't matter much because the most common game physics engines haven't changed much in the last decade as far as I know.
But I'm no expert. I just have a lot of experience using the available physics engines in Godot.

And I also approached it the opposite way of what you are doing right now, by using the available features the physics engine provides to let me guide to my solution instead of trying to apply physics theory to physics game engines.
I think that approach is problematic and in most of the cases I've seen the understanding of the physics engine is the ( only ) important thing and there's almost no benefit from a great expertise of physics in general.

You could probably compare it to race car drivers: to be the fastest driver it's not necessary to know any tire friction formulas or be able to compute the air resistance at certain speeds.
And knowing all those formulas won't make you a good racing car driver..