Animations and Collisions

I’m having a problem with the collision system detecting hits when the item is re-parented and being animated.

Im using the below to check for collisions

this.entity.parent.collision.on('collisionstart', functiom(){
    if(ent.other.name ==="Sword" ){
        this.health--;
    }
}, this);

Then using the animation system to animate the sword to strike. I might not understand the collision system as good as I thought!

Link to editor: https://playcanvas.com/editor/scene/918959

Thank you for your help in advance!

Hi @Scottss,

What are the steps to reproduce your issue?

Also in the code above you need to change the word functiom to function.

1 Like

Re-parent an object, then test the collision. My expected result was that the collision.on(‘collisionstart’) event to be called but it never is. Have you had any of these issues?

Hi @Scottss,

Picking the weapon and then approaching the enemy, whenever the weapon touches the enemy a collision result is registered in the console. I think it’s working:

I think thats the result of the player and enemy colliding, my anticipated result is the ContactResult.Other.name = “Sword”

ps: you can swing with left click, you might need to walk while clicking so that it checks if its clicked :sweat_smile: