Character Body to Rigid Body 3D Physics Interaction | Godot 4 Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ม.ค. 2025

ความคิดเห็น • 40

  • @AirmanCS
    @AirmanCS 7 หลายเดือนก่อน +7

    Love the ending bc is true I tried to do a 3D breakout bc it was "simple" and I almost end up, calculating all normals and velocities by hand xD, at the end I conformed myself with a decent result and left it as a nice prototipe of a simple game that I will polish if necessary, but physics took me by surprise when they are part of the gameplay

    • @MichaelGame_Dev
      @MichaelGame_Dev 4 หลายเดือนก่อน

      Doing a 3d breakout now. Personally, I would recommend a characterbody for the ball and paddles just due to this. I'm using rigidbody's for the bricks. I want some of the bricks to slide. I can get them to move, but it doesn't feel right, so digging into that some.

  • @nick12791
    @nick12791 8 หลายเดือนก่อน +4

    Keep them coming I'm here for it, another amazing video!

  • @LD_Anvil
    @LD_Anvil 7 หลายเดือนก่อน +1

    Special thanks to you, I have looked around for physics interaction for a long time with no result.

  • @konstryktor34
    @konstryktor34 7 หลายเดือนก่อน +2

    I can finally implement physics in my game with character bodies. It was a big problem for me, cause I am not a coder, but i wanted it so bad! Learning something new everyday. Definitely like and subscribe.

  • @Doom_C
    @Doom_C 7 หลายเดือนก่อน +1

    Funny that you upload this, was just messing around with your old source code earlier today to check if physics was applied to objects.

  • @jamesbogart3334
    @jamesbogart3334 5 หลายเดือนก่อน

    Thanks, this worked great and was exactly what I needed. No other good answers for this that I could find.

  • @deathsyrup
    @deathsyrup 8 หลายเดือนก่อน +6

    Top tier 💯

  • @TRUFANATIC
    @TRUFANATIC 8 หลายเดือนก่อน +2

    Bro! You are my hero, thank you, your videos is exactly what I wanted!

    • @MajikayoGames
      @MajikayoGames  8 หลายเดือนก่อน +2

      :D more to come. going to keep building out this fps controller/game for a while.

    • @Doom_C
      @Doom_C 7 หลายเดือนก่อน +1

      @@MajikayoGames You're the man. ATM this is by far the best fps controller out there for Godot, and I've checked a lot of them.

  • @ignis621
    @ignis621 6 หลายเดือนก่อน +1

    thanks man! ive been getting used to godot and your videos are a great help. you're awesome!

    • @MajikayoGames
      @MajikayoGames  6 หลายเดือนก่อน

      awesome!! glad you're enjoying :)

  • @Furiac.
    @Furiac. 27 วันที่ผ่านมา

    thank you so much. it works but now I just need to study the code some more and understand it.

  • @tomasz9429
    @tomasz9429 7 หลายเดือนก่อน +3

    You can get some funny results while playing around with the BOUNCE property on the RigidBody3D. Managed to launch myself into space again after colliding with two objects which had bounce set to 1. I saw Azathoth this time. Wouldn't recommend.

  • @oddlytimbotwillison6296
    @oddlytimbotwillison6296 6 หลายเดือนก่อน +1

    Very nice! A good primer for rigidbody interactions.

  • @UltimatePerfection
    @UltimatePerfection 7 หลายเดือนก่อน +2

    I've just used a rigid body for my character. I realize that I have made it harder on myself in some ways, but I can work around those issues and as a bonus I don't have to worry about making it possible for the character to be moved by a moving obstacle in physically accurate manner (i. e. character flies away after being hit by an oversized hammer) and weird collision issues such as character being stuck in the walls or whatever as the physics engine will do that work for me.

    • @MajikayoGames
      @MajikayoGames  7 หลายเดือนก่อน

      Yes this is definitely one possible solution, this could be good for a lot of games. I probably should have mentioned this in the video too. Like you said it could have some downsides but all depends on what type of game you're making.

    • @UltimatePerfection
      @UltimatePerfection 7 หลายเดือนก่อน +1

      @@MajikayoGames 3D platformer, actually.

    • @Hazan12345
      @Hazan12345 5 หลายเดือนก่อน

      What problems have you face using rigid body for your controller? Curious to know the ups and downs of each type for godot

  • @GeneralChrisGaming
    @GeneralChrisGaming 2 หลายเดือนก่อน +3

    Ice heavier than player
    Also player: fall faster

    • @MajikayoGames
      @MajikayoGames  2 หลายเดือนก่อน

      yeah im not sure why that happened tbh 🤣🤣

  • @luigirapetta7651
    @luigirapetta7651 13 วันที่ผ่านมา

    Very informative video. Thanks a ton.

  • @galvanizeddreamer2051
    @galvanizeddreamer2051 9 วันที่ผ่านมา

    Oh, you want glitchy rigid body physics? Check out the barrels in Deep Rock Galactic. Stand on those things, and you and it will go to the moon.

  • @rupertkemsley7166
    @rupertkemsley7166 23 วันที่ผ่านมา

    Hey, great tutorial!
    I was wondering if you could help with something. How would you go about implementing the character RigidBody3D physics interaction, but only in the y direction?
    I have this seesaw-like object in my game (a long, thin plank of wood resting over the edge of a pit), which is also a RigidBody3D. I've been trying to figure out how to make it so that the player, who has mass, can cause the seesaw to tilt based on their weight and where they’re standing on it.
    Any tips would be really appreciated!

  • @bardmask9089
    @bardmask9089 3 หลายเดือนก่อน +1

    im having problems with this method, first my character has deceleration instead of instantly stopping which makes the rigidbodies "stick" to the player if he moves slowly, also theres an issue where the rigidbody can "phase" through other colliders when pushed directly into them.

  • @LopkaUna
    @LopkaUna 4 หลายเดือนก่อน

    works flawlessly!
    i also strict height of collision with
    [if self.global_position.y - get_slide_collision(clsns).get_position(cldrs).y < 0.9:]
    so i got no issues with walking on little objects

  • @PastaMaster115
    @PastaMaster115 7 หลายเดือนก่อน +1

    It doesn't appear to be working. I don't have the weight shapes you have in the video. But I'm playing with the colored cubes and spheres, which I can see already came with programmed masses. 10s, 7s, 5, and 1s. But it seems they all push exactly the same. I've even increased their masses to 1000 and still get the same result. I even copied your code directly to see if I did something wrong. I could see you got way more resistance from the bigger shapes. With me that's not happening.

    • @MajikayoGames
      @MajikayoGames  7 หลายเดือนก่อน

      maybe because they are spheres, easier to push, but yes it's not a perfect method, it would be very difficult to get perfect physics interaction. this is just a simple method to apply some force when pushing against objects. as i said at the end, for more complex cases you would probably want to program it in yourself.

  • @Mrtargi
    @Mrtargi 6 หลายเดือนก่อน

    Do you have Idea how can Character body attach rigid body to itself or drag or pull it?

  • @graphtet3751
    @graphtet3751 7 หลายเดือนก่อน +1

    After I tried this my character in game is not moving when i try to move i am not receiving any errors but i can’t move my player character how do i solve this

    • @MajikayoGames
      @MajikayoGames  7 หลายเดือนก่อน

      can't think of why that would happen. you're talking about with the _push_away_rigid_bodies function? does it still work if you comment out the function call before move and slide? and you are still calling move_and_slide right?

    • @graphtet3751
      @graphtet3751 7 หลายเดือนก่อน +1

      @@MajikayoGames I went back through to check the move and slide and found out that the problem was i placed the function inside the physics process after moving the push rigid bodies function above the physics process it started working as intended

  • @Mrtargi
    @Mrtargi 6 หลายเดือนก่อน

    Thank you for tutorial! I have a strange issue that everything is working perfectly with small weights, but if I put it for example 30kg it is really hard to move, no matter what weight does my character have. Tried to play with friction option but it does not help. What could it be? Or I'm not seeng obvious? I'll provide a code snippet under that comment. Thanx in advance

    • @Mrtargi
      @Mrtargi 6 หลายเดือนก่อน

      extends Node
      class_name MovementController
      @export var player : Player
      @export var mesh_root : Node3D
      @export var rotation_speed : float = 8
      @export var fall_gravity : float = 45
      var direction : Vector3
      var velocity : Vector3
      var cam_rotation : float = 0
      var player_init_rotation : float
      var acceleration : float
      var speed: float
      func _ready():
      player_init_rotation = player.rotation.y
      func _physics_process(delta: float) -> void:
      velocity.x = speed * direction.normalized().x
      velocity.z = speed * direction.normalized().z

      if not player.is_on_floor():
      velocity.y -= fall_gravity * delta

      player.velocity = player.velocity.lerp(velocity, acceleration * delta)
      _push_rigid_bodies()
      player.move_and_slide()

      var target_rotation = atan2(direction.x, direction.z) - player.rotation.y
      mesh_root.rotation.y = lerp_angle(mesh_root.rotation.y, target_rotation, rotation_speed * delta)

      ## Debug prints
      #print("Direction: ", direction)
      #print("Velocity: ", velocity)
      #print("Player Velocity: ", player.velocity)
      #print("Target Rotation: ", target_rotation)
      #print("Mesh Root Rotation Y: ", mesh_root.rotation.y)
      func _push_rigid_bodies():
      for i in player.get_slide_collision_count():
      var c := player.get_slide_collision(i)
      if c.get_collider() is RigidBody3D:
      var push_dir = -c.get_normal()
      # How much velocity the object needs to increase to match player velocity in push direction
      var velocity_diff_in_push_dir = player.velocity.dot(push_dir) - c.get_collider().linear_velocity.dot(push_dir)
      # Only counts velocity towards push dir, away from character
      velocity_diff_in_push_dir = max(0., velocity_diff_in_push_dir)
      # Objects with bigger mass than us should be harder to push. But should not be pushed faster than we are moving

      var mass_ratio = min(1., player.PLAYER_APPROX_MASS_KG / c.get_collider().mass)

      # Don't push object from above below
      push_dir.y = 0
      var push_force = mass_ratio * 5.0
      c.get_collider().apply_impulse(push_dir * velocity_diff_in_push_dir * push_force, c.get_position() - c.get_collider().global_position)

      func _on_set_movement_state(_movement_state : MovementState):
      speed = _movement_state.movement_speed
      acceleration= _movement_state.acceleration

      func _on_set_movement_direction(_movement_direction: Vector3):
      direction = _movement_direction.rotated(Vector3.UP,cam_rotation + player_init_rotation)
      func _on_set_cam_rotation(_cam_rotation : float):
      cam_rotation = _cam_rotation

  • @picnic-in-the-oblivion
    @picnic-in-the-oblivion 6 หลายเดือนก่อน

    Hello, I've used _push_away_rigid_bodies() function, put it before move_and_slide() all works good, but when I jump on the rigidbody3d object it behave very weird and glitchy (I try to stand on barrel mesh, so when Its moved and I jumped on it, barrel with pushed away very fast and fly away :D)

    • @SomeWhiteGuy1
      @SomeWhiteGuy1 5 หลายเดือนก่อน

      same problem, found a way to fix it yet?

    • @bananabarddev
      @bananabarddev 4 หลายเดือนก่อน

      Probably forgot to change the Y value in push_dir Vector3 to 0

  • @Ver2ion
    @Ver2ion 4 หลายเดือนก่อน

    im trying to get this code to stop working if the player is above or on top of the object because if i stand on an object they will start to get impulses until the object like explodes and i go flying off of it lol
    UPDATE:
    put this after push_dir for more better accurate results without glitches and launching in the air
    if abs(push_dir.y) > 0.1: # Adjust this threshold if needed
    continue