Hello everyone.
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?
So one trick that you could use is to add a collision entity as child to the animation bone node that is responsible for the rotation animation.
That way the collision entity will rotate together with animation. Though note if you are using rigid bodies, that will work with a kinematic body only.
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.
Thank you.
@Leonidas
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?
You can access the different components of your model in code by diving into entity.model.meshInstances. It contains an array of the different mesh objects in the model.
@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.
Currently, I’m trying the above method. But while raycasting, the result is still undefined.Is this the proper way or is there any other way to do it?
Thank you
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
@Leonidas Thank you for your reply.
Now I have added a separate entity as a child to act as a collider and used tween to match the door’s animation as you suggested above. It seems to work fine now.