Open msub2 opened 3 years ago
Okay I don't know the answer (yet) but my first instinct would be to try using a constraint like the "target" property to point the ammo-shape at the camera or player's head. That constraint or property seems to create a visual binding between two entities, which you can see in the Aframe Physics Examples.
Revisiting this one after a little bit. I tried using a constraint but it had no visible effect, and I'm not sure it would have worked to begin with given that the head is a child object of the body. All I've been able to determine is that the offsets/half-extents seem to update exactly once, and no matter what I try to modify the debug drawer shows that there's been no change. I even tried accessing the localTransform of the collisionShape and setting the origin from there, but still nothing.
EDIT: I think I've figured out what the problem is. I don't think you're able to update the btCollisionShape you get from your three-to-ammo conversion during runtime; it only sets the offset/halfExtents when it's initialized. I tested this by removing and readding the ammo-shape component with updated values every tick, and the collider is finally behaving as expected. Code for reference:
this.player.removeAttribute('ammo-shape');
this.headPos.setFromMatrixPosition(this.head.object3D.matrixWorld);
this.player.setAttribute('ammo-shape', {
type: 'capsule',
fit: 'manual',
halfExtents: `.15 ${this.headPos.y / 2} .15`,
offset: `${this.headPos.x - this.player.object3D.position.x} ${this.headPos.y / 2} ${this.headPos.z - this.player.object3D.position.z}`
});
Updated Glitch project showing proper functionality: https://glitch.com/~aframe-physical-character-controller
I'm currently attempting to make an ammo-shape follow the location of a player's head to properly position/adjust a capsule body collider for VR. When I set the values of the offset or halfExtents it doesn't affect the collider at all, which I can see with debug draw on. But if I log the values of either, they come back with the values I expect.
Relevant code:
Full demo here: https://glitch.com/~aframe-vr-character-controller I'm at a bit of a loss on what could be causing this. If I'm somehow misunderstanding something or more information is needed, just let me know.