#2+ contacts reported problem

1 messages · Page 1 of 1 (latest)

red dew
#

Why, when I do two or more contacts monitored, is there another contact somewhere among those three dots? (They're guesess cuz I can't get drawing to render in the right position)
The dot on the bottom is the expected contact, which happens with only one, but then there's another dot around the knee that shouldnt be there whenever i have 2+ contacts max
(all the bodies in the stick figure have collision exceptions with eachother)

#

making them not collide via removing the layer from the mask did not solve the issue

red dew
#

bunp

cosmic bluff
#

Give this a try

extends Node2D

var _objects: Array[RigidBody2D]
var _points: Dictionary[String, Vector2]


func _ready() -> void:
    for obj: RigidBody2D in get_tree().current_scene.find_children("", "RigidBody2D"):
        if obj.contact_monitor and obj.max_contacts_reported > 0:
            _objects.append(obj)
            print("monitoring %s" % obj.name)


func _physics_process(_delta: float) -> void:
    for obj in _objects:
        var state := PhysicsServer2D.body_get_direct_state(obj.get_rid())
        var n: String
        for i in state.get_contact_count():
            var node: Node = state.get_contact_collider_object(i)
            n = "%s: %s" % [obj.name, node.name if node else state.get_contact_collider_id(i)]
            _points[n] = state.get_contact_collider_position(i)
            queue_redraw()


func _draw() -> void:
    draw_set_transform_matrix(transform.affine_inverse())
    for p in _points:
        draw_string(ThemeDB.fallback_font, _points[p], p)
    _points.clear()
#

attach it to the scene root or something. It should draw all the collisions and names

red dew
#

I had that code print what it sees, which is the second set of text, and the first set of text is the nodes reporting their own collisions

#

So the nodes are seeing, like, ghost collisions or smth

#

this shows more info

#

but yeah

#

Also heres the code on the stickman for ground check

        if grounder.get_contact_count() > 0:
            for i in grounder.get_contact_count():
                var body_state = PhysicsServer2D.body_get_direct_state(grounder.get_rid())
                print("! %s: %s: %s" % [grounder.name, body_state.get_contact_collider_object(i).name, str(body_state.get_contact_local_position(i))])
                if abs(body_state.get_contact_local_normal(i).angle_to(Vector2.UP)) <= deg_to_rad(45):
                    var dist = body_state.get_contact_local_position(i).distance_to(head.global_position)
                    if dist < distance_from_head_to_ground:
                        distance_from_head_to_ground = dist
                    is_grounded = true
                    is_on_wall = false
                    wall_normal = Vector2.ZERO
                elif abs(body_state.get_contact_local_normal(i).angle_to(Vector2.UP)) <= deg_to_rad(95) and not is_grounded:
                    is_on_wall = true
                    wall_normal = body_state.get_contact_local_normal(i)```
#

(@cosmic bluff )

#

also just determined that this only happens on rapier

#

But pin joint constraints dont work in godot's default physics engine

red dew