[SOLVED] Making A Health Bar Tutorial, BUT


#1

Ive made the script right and everything works out until u launch… When u launch the health bar appears below your body and doesnt follow the camera:


But when im in the editor it works just fine:
18%20PM%20-%20Edited
Here ive looked for the problem for the past 2-3 hours and cant seem to find ANY problem and ik how to do this but something is off but eberything checks out if anyone can find an issue let me know

var Health = pc.createScript('health');

// initialize code called once per entity
Health.prototype.initialize = function() {
    this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
    this.app.keyboard.on(pc.EVENT_KEYUP, this.onKeyUp, this);
    this.scaling = 0;
    this.add = 0.25;
    this.subtract = -0.1;
    this.initialScale = this.entity.getLocalScale();
    this.cameraEntity = this.app.root.findByName('CameraPlayer');
    
};

// update code called every frame
Health.prototype.update = function(dt) {
    var currentScale = this.entity.getLocalScale();
    
    if (currentScale.x < 0.01)
        {
            currentScale.x = 0;
        }
    if (currentScale.x > 50)
        {
            currentScale.x = 50;
            this.scaling = 0;
        }
    
        {
            this.scaling = 0;
        }
    currentScale.x -= this.scaling;
    this.entity.setLocalScale(currentScale);
};

because im gonna take a break ill be back soon if u can help i thank u very much!
Nathan Hawkins!
https://playcanvas.com/editor/scene/722434


#2

Do you mean in the editor itself or when you launch the scene to test from editor? Can you post a link to a public project that shows this issue please?


#3

https://playcanvas.com/editor/scene/722434


#4

As far as I can tell, the health bar is not in the camera view:

image


#5

Click launch then look at the screen and u will see. Dont move the camera when u launch


#6

Just looks like this to me:


#7

18%20PM%20-%20Edited
Looks like this for me


#8

@yaustar Now it should be completely gone right? even if u look around its not there? Fixed now ty


#9

Looks fine now

2020202


#10

Yup ty for your help