Enemy health bar doesn't rotate towards camera

Hi!

I’m asking after trying to solve this by myself, but I just don’t know what is working wrongly. I just followed every step, the enemy health bar instantiates correctly, console isn’t showing any error or warning message but the enemy’s health bars just doesn’t rotate, they stay just static with the predefined rotation.

I checked that the camera is being recognized as the main camera, in fact I added it manually using the inspector, but It doesn’t work.

Tested with Unity 2017.4.1.f1 and 2018.1.0f2

The script of enemyUI isn’t modified, tried to use Update and LateUpdate, still the same.

EDIT: Forgot to say, I’m working using MacOS High Sierra 10.13.4

I feel your pain, on a pc here with unity 2018.1.6f1 and my enemy bars a) make my enemies turn with keyboard controls (which I never asked them to, and didnt happen until this was added), b) my enemy health bars are under their feet… c) turn, but because I dont have a fixed camera, I wanted the float behind kind, its not pointing at my camera…

Just as I think im getting the hang of something, it all goes pear shaped.

On top of that, now even undoing all the stuff my player mouse move now makes the guy spin like an idiot which it didnt do before trying this section but undoing and reverting isnt helping.

I have found a workaround for this problem, I use one canvas in screen position and instantiate health bars for every character, but the health bars stays in the canvas and update themselves based on the worldpoint to screen point.

this is what I use:

    public static void UpdateObjectPosition(Vector3 worldTargetPosition, GameObject canvasObject)
    {
        Vector2 canvasPos = instance.WorldToCanvas(worldTargetPosition);
        canvasObject.GetComponent<RectTransform>().anchoredPosition = canvasPos;
    }

      public Vector2 WorldToCanvas(Vector3 worldPosition)
    {
        Vector3 position = Camera.main.WorldToViewportPoint(worldPosition);
        if (position == Vector3.zero)
            position = Camera.main.WorldToViewportPoint(new Vector3(worldPosition.x, worldPosition.y, Camera.main.transform.position.z + 1));

        float xPos = (position.x * canvasRectTransform.sizeDelta.x) - (canvasRectTransform.sizeDelta.x * 0.5f);
        float yPos = (position.y * canvasRectTransform.sizeDelta.y) - (canvasRectTransform.sizeDelta.y * 0.5f);
        return new Vector2(xPos, yPos);
    }

And within the healthbar script:

PlayerFeedback.UpdateObjectPosition(target.transform.position + Vector3.up * healthBarUpOffset, gameObject);

But this versions is a early version, need to change a few things to improve performance

Privacy & Terms