0 votes

I have built a minimal example and I can't get it to work with RigidBody2D nodes. It will report collisions with StaticBody2Ds and other KinematicBody2Ds

have a bullet that is on collision layer 2, with mask on 3

func _physics_process(delta):
var movement = direction * speed * delta
var collision = move_and_collide(movement)
if collision:   
    print(collision.collider.name)

I have set up 3 targets, all on collision layer 3, a Rigidbody2D a StaticBody2D and a KinematicBody2D.
If I fire at each of them in turn the bullet stops at both the Static and Kinematic and move_and_collide() returns a KinematicCollision2D object. In the case of the Rigidbody, the bullet hits and moves the RigidBody2D but move_and_collide() returns nothing.

Am I right in saying that move_and_collide() should return something when colliding with a RigidBody2D? The docs are not entirely clear on this point.

Godot version 3.4.4.stable
in Engine by (15 points)

1 Answer

0 votes
Best answer

The docs are entirely clear on this point. This is expected behavior when infinite_inertia is on:

If infinite_inertia is true, body will be able to push RigidBody2D nodes, but it won't also detect any collisions with them. If false, it will interact with RigidBody2D nodes like with StaticBody2D.

https://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html#class-kinematicbody2d-method-move-and-collide

by (21,716 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.