I want to make a Flappy Bird game i have the player that is RigidBody2D and pipes they are KinematicBodys2D.
When im trying to detect collision from pipe script with collision = move_and_collide() it`s just dont detect collisions with RigidBody2D

  • ajay replied to this.

    Collisions between a RigidBody2D and a KinematicBody2D should work.

    What is a pipe script?

    Can you post your project somewhere so that we can see it?

      DaveTheCoder

      I think OP means the script attached to the kinematic bodies (the pipes) in the flappy bird game...

      DIO_27

      Why are you using Kinematic Bodies for the Pipes? Are they moving? I thought the pipes were like obstacles and the flappy bird is moving... Anyways, I would script a collision thus...

      var crash = move_and_collide(direction*speed*delta)
      if crash:
        do_something()

        ajay imo it is easier to do pipes move than move player. I know that i can write thing that you wrote, but main problem it is that when im write coll = move_and_collide()
        If coll:
        print(smth)
        It is works when pipes colliding with kinematic body but not RigidBody

        ajay I saw this, I'm making literally the same thing and its work only with kinematic body

        I'll repeat: Can you post your project somewhere so that we can see it? Or another minimal project that has the issue? (Don't include the .import subfolder.)

        There are various reasons why it could be failing to work. Seeing the whole project makes it much easier to find the cause.

          I wasn't able to extract the files from the .rar. But maybe someone else can look at it.

          Are you using C# scripts in the project? It has a .mono subfolder.

            I was able to duplicate the problem. I can see the objects colliding visually, but move_and_collide() returns null. I don't know why.

              DaveTheCoder very sad, so i am going to do player KinematicBody and move it down every frame

              It occurred to me that the problem may be that the KinematicBody2D is pushing the RigidBody2D away, so that their collision shapes never actually overlap.

              If I change the mode property of the RigidBody2D to MODE_KINEMATIC, then the RigidBody2D doesn't get pushed, and a collision is detected. However, the collision shapes doesn't overlap in this case either, so my reasoning above may be faulty.

              Ok, this worked... in Player.gd:

              extends RigidBody2D
              
              func _ready():
              	pass
              func _integrate_forces(state):
              	if Input.is_action_just_pressed("Jump"):
              		apply_impulse(Vector2.ZERO, Vector2(0, -300 - linear_velocity.y))
              func _physics_process(delta):
              	var crash = get_colliding_bodies()
              	print(crash)
              	pass

              get_colliding_bodies()

              ● Array get_colliding_bodies() const

              Returns a list of the bodies colliding with this one. Requires contact_monitor to be set to true and contacts_reported to be set high enough to detect all the collisions.

              Note: The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.