Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

ammo-shape offset and halfExtents seemingly not updating even after setting values #177

Open
msub2 opened this issue Oct 18, 2020 · 2 comments
Assignees

Comments

@msub2
Copy link

msub2 commented Oct 18, 2020

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:

let headPos = this.head.object3D.position;
let ammoShape = this.player.components['ammo-shape'].data;
ammoShape.offset.x = headPos.x;
ammoShape.offset.y = headPos.y / 2;
ammoShape.offset.z = headPos.z;
ammoShape.halfExtents.y = headPos.y / 2;

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.

@n5ro
Copy link
Owner

n5ro commented Nov 9, 2020

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.

@msub2
Copy link
Author

msub2 commented Dec 29, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants