I want to make a bar that shows a variable like bullet regeneration time. I know that to do this I need to change the scale parameter given to Entities.
But when I tried to change the scale parameter, the bar goes in two directions (left and right) when it should normally go in one direction. I watched some tutorial(Tutorial) but it didn't worked for me.
Here is my code:
if mermiat == False and mertim >= 0.5:
mermiat = True
mertim = 0
elif mermiat == True and mertim >= 0.5:
mertim = 0
if mermiat == True:
BulletBar.scale_x = 12
if mermiat == False:
BulletBar.scale_x = mertim * 24
Player = Karakter()
BulletBar = Entity(model = "quad", position = (-13,-9,-2),scale=(12,0.5,1), color="FFFF00")
"""
Notes:
mermiat: bool variable to shotting bullets. If it is True, Player can shot Bullets.
mertim: timer for shotting bullets. It blocks spawning bullets.
Karakter(): Player class
in the player class(Karakter) mertim is updating.
If blocks is in the Player class(Karakter), at the update function.
"""
I can't test it but I found documentation ursina engine coordinate system which describes Origin
I also watched tutorial and it has code also with origin
full_bar = Entity(..., origin=(-.5, -.5), ...)
but you don't use it. And this can make problem.
As default objects use origin=(0,0,0)
which means center
of object - so when you scale then it keeps this center in original place, and this resizes in both directions.
If you set origin=(-.5, 0, 0)
then it should use left-side
for x
(and center
for y
, and center
for z
) and it should keep left-side
in original place, and it should scale to the right.
But I'm not sure but it may need to set position
with different value x
because it may need to move width/2
to the left to get the same position as before.
if you use origin=(.5, 0, 0)
then it should use right-side
for x
and it should keep right-side
in original place, and and it should scale to the left.
Source code: Entity (with origin=Vec3(0,0,0)
)