Get name of colliding object

I currently got a collision listener added in Add. How can I check if this object has a certain name?
I need to make sure it is one of two object types. I already checked the event variable, but that had no clear name.

Current code:

add: (world, component) => {
    const {eid, dataAttribute} = component

    const checkCollision = ((e) => {
      const data = dataAttribute.cursor(eid)

      // Get collision name
      const name = 'Left'

      if (name === 'Left') {
        data.correctCount++
      }
      console.log(e)
    })
    world.events.addListener(component.eid, ecs.physics.COLLISION_START_EVENT, checkCollision)
    // Runs when the component is added to the world.
  },
1 Like

To check the colliding object’s name, access its property from the event data (e.g., e.other.name). Update the check Collision function to compare the name with your desired values (“Left” or “Right”). Increment data. correct Count if a match is found. Use optional chaining (?.) to handle undefined properties safely. Ensure your objects have identifiable name or type attributes.

No succes so far

e.data.other gives a string which is not the name
e.data.other.name is undefined.

This currently is not supported. You need to do this with eid.
I currently made a new component with export and a bool and called an event from that. Then in the listening event I get that component and the bool

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.