• Godot Help
  • Best way to update CharacterBody2D with linear_damp from AreaBody2D

I have a CharacterBody2D and a bunch of Area2Ds. I want each Area2D to slow down the character based on something like friction where each area has it's own friction value. It looks like that's what the linear_damp property in Area2D is intended for. But based on experimentation CharacterBody2D doesn't seem to be impacted by linear_damp which makes sense because it's kinematic not rigid. So I guess I need to code my CharacterBody2D to use linear_damp when it enters the Area2D?

The only way I see to do that is to connect the character to the body_entered(Node2D) signal from Area2D. But the problem is my handler function in CharacterBody2D gets itself as the argument not the Area2D that emitted the signal.

extends CharacterBody2D

func _on_area_2d_body_entered(body):
	pass # body == self :(

I don't see an obvious way to get the linear_damp value from the Area2D that emitted the signal. I could create a custom node that extends Area2D and create a custom signal in it that sends linear_damp as an argument but before I do that I wanted to check with more experienced people whether this is the best solution. Is there a more built-in/natural way to do this or do I need to make a custom node and signal?

P.S. I'm supposed to tag this as Godot 4 but I don't see how do that.

Thanks!

  • I searched through the engine source code for ideas. As far as I can tell colliding with areas and linear_damping is handled inside the 2d physics engine and never exposed in gdscript. I can get info about collisions with other physics bodies in gdscript but not collisions with areas. So I think the solution I described above is the best solution. I'll go with that.

I searched through the engine source code for ideas. As far as I can tell colliding with areas and linear_damping is handled inside the 2d physics engine and never exposed in gdscript. I can get info about collisions with other physics bodies in gdscript but not collisions with areas. So I think the solution I described above is the best solution. I'll go with that.