2

I have created a simple life bar using css.

#enemy {
    background-color: black;
    border-radius: 7px;
    padding: 3px;
    width: 100px;
}

#enemy div {
    background-color: green;
    width: 100%; 
    height: 20px;
    border-radius: 5px;
}

I have to move the bar on top of the head of my collada model. how can i assign position of model to bar using jQuery? here is the code i tried but it doesn't work

    var count =0;
        for (var i = ai.length-1; i >= 0; i--) {
            var a = ai[i];
            // Move AI
        var r = Math.random();
            var c = getMapSector(a.position);

$('#enemy div').css({'position':'relative', 'top':c.z, 'left':c.x,});

            if (c.x < -1 || c.x > mapW || c.z < -1 || c.z > mapH) {
                ai.splice(i, 1);
                scene.remove(a);
                addAI();
            }
            }


function getMapSector(v) {
    var x = Math.floor((v.x + UNITSIZE / 2) / UNITSIZE + mapW/2);
    var z = Math.floor((v.z + UNITSIZE / 2) / UNITSIZE + mapW/2);
    return {x: x, z: z};
}
4

0 回答 0