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.
},
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.
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