Is it possible to change the collision component along with the object’s animation?
I have a door object with animation and I have placed a car behind the door.
I have placed the camera in front of the door.
When I use raycast and the door is closed, I get raycast result as Door, but when the door is open and then I use raycast, I still get the raycast result as Door. Is there a way that the raycast hits the car when the door is open?
Yes, you can attach entities to the bones of a skinned animation (search the forums on how to do that, there are a lot of posts), and those entities will rotate automatically. It can be tricky to get the right rotation if the bones aren’t set to move/rotate on a single axis, as I see here:
Otherwise, you can mimic the same behavior with the tween library, and try to rotate your collision entity in code, when the animation starts. To match the movement of the door. Check here on how to use the PlayCanvas tween lib:
@Leonidas Thank you for your reply.
We have a different problem now. Actually the door is one of the mesh instances of the entire model and only door has the animation. So is it possible to add collision component to one of the mesh instances?
If possible, any link would be really helpfull.
In the above project, you can see that when I imported the house model, I can’t access its hierarchy in the editor. Is there a way to access it programmatically?
I have imported the same model in https://threejs.org/editor/ and I can see the hierarchy and access each part. Is that possible in playcanvas?
@eproasim Thank you for your reply.
But I want to add a collision component to one part only(for example, only to the door of the entire house model).
Currently, I’m trying using this.entity.findByName() to find the graph node.
Graphnodes can’t have components. You could create a new Entity with the collision and add it as a child of the graphNode bearing in mind that it will be affected by the transformation of the hierarchy.
Or alternatively, you can have a separate Entity with the collision and set the position and rotation of it to be the same as the graph node every frame.
There was a demo someone did that I can’t find where they attached physics object to a sword attack animation @leonidas, do you know the one I’m thinking of? I think it was by a Japanese developer