This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

3D rigid body character

GalidraanGalidraan Posts: 9Member

Hello, I try to create a player character.
I want use a rigid body node, because I don't want to program all the micro-interactions.
I had succeed to create a player's behavior with the apply_impulse method, but it isn't perfect, and I hope to find a solution on this forum.
My principal problems are :
-sometime the players locks, mainly on the edge of the land shape
-on the mounted, the player's speed decrease very strong (it's normal, but I haven't idea to keep a nearly constant speed )
-after a running, the player glide
-sometime the player go inside the ground

All this problems make me think that the method "apply_impulse" isn't appropriate. I think that the best would be a method similar to "move_and_collide", but "translate" don't work on a rigid body

Answers

  • MagicLordMagicLord Posts: 578Unconfirmed
    edited March 2018

    @Galidraan said:
    Hello, I try to create a player character.
    I want use a rigid body node, because I don't want to program all the micro-interactions.
    I had succeed to create a player's behavior with the apply_impulse method, but it isn't perfect, and I hope to find a solution on this forum.

    -sometime the players locks, mainly on the edge of the land shape

    This happened to me with a capsule blocking in the edge of a cube, smooth your landscape or make bevel to avoid sharp corners.

    -on the mounted, the player's speed decrease very strong (it's normal, but I haven't idea to keep a nearly constant speed )

    decrease your static ground physics friction and decrease your player rigidBody friction , it should slide

    -after a running, the player glide

    You can apply an additional negative gravity on Y axis when you use add_impulse

    -sometime the player go inside the ground

    Above some speed this can happen.
    Use a Raycast to floor determine the ground height the player position on Y.
    When the player Y value is below a treshold use velocity.y =-0.1 to avoid it to go through ground.

    The best solution for character controllers is to use KinematicBody to avoid those problems.
    For example this tutorial should help you create a controller that should work fine.
    https://youtube.com/watch?v=Etpq-d5af6M

  • GalidraanGalidraan Posts: 9Member

    Thank you for your answer, but I realized that your solutions are very difficult to use it and necessitate a lot of adjustment.
    I tried the set_linear_velocity method, and the result is very mush less random. But when I use it, all the force isn't applicate, and the character don't fall, there are way around this problem?
    (sorry for my bad English I hope that this message is understandable)

  • MagicLordMagicLord Posts: 578Unconfirmed

    @Galidraan said:
    Thank you for your answer, but I realized that your solutions are very difficult to use it and necessitate a lot of adjustment.
    I tried the set_linear_velocity method, and the result is very mush less random. But when I use it, all the force isn't applicate, and the character don't fall, there are way around this problem?
    (sorry for my bad English I hope that this message is understandable)

    Because linear_velocity overrides any force.

    Copy and paste code from part one of the Fps tutorial , and you'll got a character controller working :)

    docs.godotengine.org/en/3.0/tutorials/3d/fps_tutorial/part_one.html

  • GalidraanGalidraan Posts: 9Member

    After much effort I abandoned the idea of using a rigid body.
    I think that today, we can't create a complex character with the 3D_rigid_body, this node hasn't enought useful method for this. We can surely create them, but I haven't the level.
    Maybe in the future, this node will be more complete.
    Thank for your support. But if someone has succeed to use a rigid body for his character, say it I'm interested.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    Why not use a KinematicBody?

    I’ve found it’s way easier to use KinematicBody for player/characters. The overhead is way less than using a RigidBody (in my opinion) and there’s plenty of material to use for reference. There’s the KinematicBody demo, the FPS tutorial (disclaimer: I wrote most of it), the Platformer demo, a great tutorial series by Jeremy on YouTube, and much more.

    If you really want to use a RigidBody, I would suggest looking at the dynamic character demo. I think it’s the same as the Platformer demo, but instead of using a KinematicBody for the player, it uses a RigidBody.

  • MagicLordMagicLord Posts: 578Unconfirmed

    @Galidraan said:
    After much effort I abandoned the idea of using a rigid body.
    I think that today, we can't create a complex character with the 3D_rigid_body, this node hasn't enought useful method for this. We can surely create them, but I haven't the level.
    Maybe in the future, this node will be more complete.
    Thank for your support. But if someone has succeed to use a rigid body for his character, say it I'm interested.

    Godot is managing a character controller almost the same way it's done elsewhere.
    Why don't you follow this tutorial video, it's exactly what you want a character controller
    https://youtube.com/watch?v=-CudxS6EeNA

  • SchusterSchuster Posts: 369Member
    edited April 2018

    I use RigidBody for my character but it's not a human but a...jumping disc....So I need more physics interactivity...you can use modes in RigidBody node

    • rigid
    • static
    • character
    • kinematic
      so I think RigidBody in Godot is a very useful and sophisticated
      .....what unfortunately is missing are good examples of these modes
      ......until when the Bullet physics engine will be fully integrated with Godot engine (Godot 3.2 ?) so the collisions ,etc. will be at a high level ;)
  • MagicLordMagicLord Posts: 578Unconfirmed

    @Bishop said:
    I use RigidBody for my character but it's not a human but a...jumping disc....So I need more physics interactivity...you can use modes in RigidBody node

    • rigid
    • static
    • character
    • kinematic
      so I think RigidBody in Godot is a very useful and sophisticated
      .....what unfortunately is missing are good examples of these modes
      ......until when the Bullet physics engine will be fully integrated with Godot engine (Godot 3.2 ?) so the collisions ,etc. will be at a high level ;)

    I don't understand why rigidbody can become a static or kinematic physic object ?
    There is already static and kinematic nodes, what is the advantage of RigidBody providing those functionalities ?
    At run time change the RigiBody node to become static or kinematic , bu i don't see any advantage.

  • SchusterSchuster Posts: 369Member
    edited April 2018

    MODE_RIGID = 0 — Rigid body. This is the “natural” state of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code.
    MODE_STATIC = 1 — Static mode. The body behaves like a StaticBody, and can only move by user code.
    MODE_CHARACTER = 2 — Character body. This behaves like a rigid body, but can not rotate.
    MODE_KINEMATIC = 3 — Kinematic body. The body behaves like a KinematicBody, and can only move by user code.
    ....from docs

    The advantage is , that you have a bigger control over the behavior of the object/character in the game.....with a RigidBody node you do not control rigidbody directly but only forces...if you need directly access to physics, use _integrate_forces().....by set _custom_integrator() = true ( to override the default physics behavior ) , then air friction and gravity will be disabled and you can write your custom forces.

    ....here's something from QA
    http://godotengine.org/qa/18344/rigidbody-in-kinematic-mode-vs-kinematicbody

  • GalidraanGalidraan Posts: 9Member

    Ok, thank you, for I will used a kinematic body, but maybe one day I will change my choice.
    Thank you every body :wink:

  • GalidraanGalidraan Posts: 9Member

    Sorry to re-open the subject, but I use the Schuster's video technique, it was worked good, but today, I have modify some thing in my scene and now the character often hangs several second.
    I can not put things back as before.
    Now the displacement is uncomfortable, and isn't playable.

  • SchusterSchuster Posts: 369Member

    Hello,
    ....what's the character setup...node tree hierarchy?
    ....what the Rigid body mode?
    ....what do you use to move the character?

  • MagicLordMagicLord Posts: 578Unconfirmed

    @Galidraan said:
    Sorry to re-open the subject, but I use the Schuster's video technique, it was worked good, but today, I have modify some thing in my scene and now the character often hangs several second.
    I can not put things back as before.
    Now the displacement is uncomfortable, and isn't playable.

    Can you post a zip package with a minimal demo so we can figure out what is wrong ?

  • GalidraanGalidraan Posts: 9Member

    Hello, sorry to be late, this is the file where you can find the bug :smile:
    https://drive.google.com/file/d/1hcE6_yhJRMAmhw560sh2_R6SXHKUfauG/view?usp=sharing

  • MagicLordMagicLord Posts: 578Unconfirmed

    @Galidraan said:
    Hello, sorry to be late, this is the file where you can find the bug :smile:
    https://drive.google.com/file/d/1hcE6_yhJRMAmhw560sh2_R6SXHKUfauG/view?usp=sharing

    This is big 2.7 Go, could you isolate the character and script , put them in a new simple scene and make a zip without all your media.

  • GalidraanGalidraan Posts: 9Member

    Ok this is a version with no texture, and a micro-map, be careful not to fall
    https://drive.google.com/file/d/1mfLRdFN_IrOM_i1fAmXkTa9apGA164qr/view?usp=sharing
    I think, that you can see quickly the bug

  • MagicLordMagicLord Posts: 578Unconfirmed
    edited May 2018

    @Galidraan said:
    Ok this is a version with no texture, and a micro-map, be careful not to fall
    https://drive.google.com/file/d/1mfLRdFN_IrOM_i1fAmXkTa9apGA164qr/view?usp=sharing
    I think, that you can see quickly the bug

    The root node of your character should be KinematicBody instead of Spatial, there is bugs if the root node is not a physic node.

    I made a tps template on top of your game level. The game runs fine, but the player controllers do hyper jump on floor big angle slopes :D
    KinematicBody doesn't like distance change with move_and_slide() on big angle slopes.

    This works fine
    velocity.y += delta * gravity

    This makes hyper jump on slopes
    velocity.y += delta * gravity if !is_on_floor(): velocity.y = velocity.y *1.5

    The project GitHub download link :

    https://github.com/DevMagicLord/Godot3/tree/master/bugs

    You can submit a bug on Godot GitHub about move_and_slide() bug on your game level.

    I think there is two bugs :

    • is_on_floor() is some sort of hack and can't work because there is micro contact variation when your floor is level is not planar but a terrain mesh with slopes. Raycast is the best way to detect floor.
    • move_and_slide() hyper jumps because there is some parameter value change when it is on some slope

    Perhaps you should use move_and_collide() instead.

  • MagicLordMagicLord Posts: 578Unconfirmed

    This is a fundation critical bug, i will submit it to GitHub.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.