I am using this code below to position an interface element (a gold exclamation point ! ) over the head of an NPC related to a quest/objective. I’m using Lemur so the gold exclamation point image is created using a Container that gets attached to the GUINode.
public void update(float tpf){
if(iconNode != null){ //iconNode is a blank node attached to the rootNode and located above NPC's head
if(iconNode.getParent() != null && app != null && app.getCamera() != null){
Camera camera = app.getCamera();
Vector3f screenPos = camera.getScreenCoordinates(iconNode.getWorldTranslation());
if(screenPos != null){
float width, height;
width = camera.getWidth() * 0.05f;
height = camera.getHeight() * 0.13f;
Vector3f newSize = new Vector3f(width, height, 1);
Vector3f newScreenLoc = screenPos.clone();
//adjust size based on distance from camera
float distFromCamera = camera.getLocation().distance(iconNode.getWorldTranslation());
float distScalar = 20 / distFromCamera;
if(distScalar <= 0.02f){
distScalar = 0f;
}
newSize.multLocal(distScalar);
newScreenLoc.subtractLocal(width * distScalar * 0.5f, 0, 0);
iconImageContainer.setLocalTranslation(newScreenLoc);
iconImageContainer.setPreferredSize(newSize);
// iconImageContainer.setLocalTranslation(screenPos); // issue still occurs if I uncomment this and use screenPos before centering and scaling
}
}
}
}
However, when the camera rotates, the exclamation point seems to wobble left/right in a stuttery and unpleasant way. The FPS isn’t shown in my screencap but its at a steady 55-60 for the whole video, and nothing else in the scene is stuttering
The health bars above the NPC’s head do not have the stuttery issue because I did those differently using a Geoemtry with an unshaded material that gets attached to the root node and always faces the camera, although that also isn’t perfect for other reasons… So I am in the process of trying to figure out which way is better for things like this.