Jump to content

Object position is not character position


MarianG
 Share

Recommended Posts

Hi, I'm new to babylonjs js. I worked in ThreeJS before, but babylonjs looks nice. And now a have a litle problem.

I have a human character, and a object. My character move to the object and have to take the object in the right hand. He go to the object, the object is aplied to the character skeleton, and he move like skeleton, but in front of character not in his hand. I don't know how to set object position in character hand.  If i set object.parent = character, the object disappear. Thanks for help, and sorry my english. Screen: http://prntscr.com/63rz4u

Link to comment
Share on other sites

He go to the object, the object is aplied to the character skeleton, and he move like skeleton, but in front of character not in his hand.

 

Hi bulisor - welcome to BJS forum. :)

 

An interesting question.  And I don't know that I have an answer - rather just a thought. Can the character have an invisible object - say a simple cube - in his/her right hand, and you make the object to be picked up a child of that invisible object in the right hand?

 

cheers, gryff :)

Link to comment
Share on other sites

Bulisor, thinking about the issue some more, the suggestion I made above I do not think will work as the armature is moving the vertices of meshes not the objects origins.

 

It is a very interesting question - one that is important for gaming - changing weapons for example.

 

I wonder if there is a more complex coding answer.

 

cheers, gryff :) 

Link to comment
Share on other sites

Thanks guys.

 

An interesting question.  And I don't know that I have an answer - rather just a thought. Can the character have an invisible object - say a simple cube - in his/her right hand, and you make the object to be picked up a child of that invisible object in the right hand?

 

 

This is an interesting trick. I will try it, and i will inform you about the rezults.

 

But I think the problem is somewhere here:

function attache(obj, ske, boneName){    var matricesWeights = new Array();    var floatIndices = new Array();    var boneIndice = -1;    for (var i = 0; i < ske.bones.length; i++) {        if (ske.bones[i].name == boneName) {            boneIndice=i;            break;        }    }    if (boneIndice == -1) { return; }    for (var ii = 0; ii < obj._geometry._totalVertices; ii++) {        matricesWeights[ii*4+0] = 1.0;        matricesWeights[ii*4+1] = 0.0;        matricesWeights[ii*4+2] = 0.0;        matricesWeights[ii*4+3] = 0.0;        floatIndices[ii*4+0] = boneIndice;        floatIndices[ii*4+1] = boneIndice;        floatIndices[ii*4+2] = boneIndice;        floatIndices[ii*4+3] = boneIndice;    }    obj.skeleton = ske;    obj.setVerticesData(BABYLON.VertexBuffer.MatricesWeightsKind, matricesWeights, false);    obj.setVerticesData(BABYLON.VertexBuffer.MatricesIndicesKind, floatIndices,  false);//maybe here must set one more kind of vertices, like positions or, I don;t know}

update:

 

Doesn't work with invisible object. I read in diferrent topic that bones need updateMatrix. And I try:

        object.parent =character;        object.position =new BABYLON.Vector3(0,0,0);                attache(object,character.skeleton,"joint3");        var matrix = character.getWorldMatrix().clone();        //console.log(matrix);        object.skeleton.bones['number_of_affected_bone'].updateMatrix(matrix);

Insteed of character, I used a rectangle what is animed, it bending. Screen : http://prntscr.com/644bgx. After I run code above, I obtain:  http://prntscr.com/644dhd. Almost done ;)

Link to comment
Share on other sites

The Dude object is not centered. the parent object is at 0,0,0 but all child meshes' vertices are not. Their position is, however, 0,0,0 (which can be rather confusing :-) ). The VertexData is simply not centered.

 

Thanks, that, was the problem. I fix it. Thanks again.

Link to comment
Share on other sites

One more question. :)

 

When I select my character, i put a torus under it, and set torus position, character position. It;s ok. But my character is walking on heightmap, and it climb and down.

var ray = new BABYLON.Ray(new BABYLON.Vector3(obj.position.x, ground.getBoundingInfo().maximum.y + 1, obj.position.z),new BABYLON.Vector3(0, -1, 0));    var worldInverse = new BABYLON.Matrix();    ground.getWorldMatrix().invertToRef(worldInverse);    ray = BABYLON.Ray.Transform(ray, worldInverse);    var pickInfo = ground.intersects(ray);     obj.lookAt(new BABYLON.Vector3(x1,pickInfo.pickedPoint.y,y1));    if (pickInfo.hit)    {        obj.position.y = pickInfo.pickedPoint.y;   }

It works fine, torus follow character, but i want that torus rotate automaticaly according to the ground shape, to be visible totally, not like this http://prntscr.com/66losr. Or it's not ok a torus for this, I may use other method?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...