Godot Version
v4.6.2.stable.official [71f334935]
Question
How can I get a RigidBody2D to detect collisions but be physically unaffected by the collision?
I have a CharacterBody that only calls move_and_collide(Vector2(0,0)) and RigidBodys that can bounce off of it. I would like to have the RigidBodies bounce off the CharacterBody as if it was a StaticBody
However: After the collision, the RigidBody looses some velocity, the CharacterBody gets nudged, and the CharacterBody’s move_and_collide does not return a collision.
Commenting out the move_and_collide makes the collision happen as expected, but I need to move the CharacterBody so that is not helpful.
If I am understanding correctly, I should not need a contact monitor for the CharacterBody so I do not believe that is the issue.
Minimum Code:
# RigidBody2D
extends RigidBody2D
func _ready() -> void:
print("Rigid Body Velocity ", linear_velocity)
func _on_body_entered(body: Node) -> void:
# Print Characters new position and this objects new velocity
print("\nIn RigidBody After Colision:\nCharacter Pos: ", body.position, "\nRigidBody Velocity: ", linear_velocity)
#CharacterBody2D
extends CharacterBody2D
func _ready() -> void:
print("Character Position ", position)
func _physics_process(delta: float) -> void:
var before = position
var collision = move_and_collide(Vector2(0,0))
var after = position
if collision != null: # collision is always null
print(collision.get_collider_velocity())
print(before, after)
Setup:
Create a Rigid and Character Body with Rectangle Shapes. Enable contact monitor for Rigid Body, set a velocity, and remove all damping. Create A PhysicsMaterial with 0 friction and 1 bounce.
# Resulting Output:
Rigid Body Velocity (80.0, 0.0)
Character Position (500.0, 300.0)
In RigidBody After Colision:
Character Pos: (501.0587, 300.0)
RigidBody Velocity: (-16.47706, 0.0)
As shown, the Character is moved and does not report a collision, while the RigidBody looses momentum
Background
I have a hollow circle controlled by the character that goes around “picking up” rigid bodies. When the rigid bodies are inside the circle, I do not want them nudging the circle around but I do want them to bounce around inside it. “Picking Up” happens when a RigidBody crosses the outside of the circle into the middle. I am not there yet, but I plan to do that logic with layers