1

I'm making a 3D FPS in Ursina, and I'd like to have my arm skin with the weapon as an image, not an actual 3D model. Does anyone know how to do this ? I tried with Animate from the documentation, but this loads an image as an object in my scene.

What I could do is define a quad with player as parent, and positional arguments, so that it follows me and I see it at the right place, but even this wouldn't work as the texture argument doesn't accept gifs.

So, does anyone know how to do that ?

Quantum Sushi
  • 504
  • 7
  • 23
  • Create the entity with `parent=camera.ui` to give it a position on the interface instead of the scene (world). I elaborated in an answer. – Jan Wilamowski Jun 27 '21 at 03:10

2 Answers2

2

You can load an animated gif with Animation() which creates an entity. As part of the interface you'll want to attach it to the UI:

from ursina import *

app = Ursina()
gif = 'animation.gif'
a = Animation(gif, parent=camera.ui)
a.scale /= 5 # adjust right size to your needs
a.position = (0.5, -0.5) # lower right of the screen
app.run()

You will need the imageio Python package installed to load gifs.


OLD ANSWER

The Entity you use for the gun has to be anchored to the interface using its parent parameter. Here's an example for a Minecraft-style hand (just a block really):

class Hand(Entity):
    def __init__(self):
        super().__init__(
            parent=camera.ui,
            model='cube',
            position=Vec2(0.5, -0.3),
            scale=(0.2, 0.2, 0.5),
            rotation=(150, -30, 0)
        )

The important part is parent=camera.ui

Jan Wilamowski
  • 3,308
  • 2
  • 10
  • 23
  • Thanks, but I know how to do this ; it's not what I meant. What I mean is : is there a way i can show an image on screen, that's not a 3D model ? So my armes aren't a cube, minecraft-like, but rather a 2D image that I can see. Like, you got your health bar : that's not a 3D model that follows you, it's 2D on the screen, and I'd like to have an image this way – Quantum Sushi Jun 27 '21 at 09:41
  • make it a `quad` and set your texture – Jan Wilamowski Jun 27 '21 at 11:03
  • Yeah, but did you read what I wrote ? The texture doesn't accept gifs or animated things, meaning I have my hands, but can't animate them – Quantum Sushi Jun 27 '21 at 15:28
  • You didn't mention animated gifs before, you merely talked about an image. I'm not sure if Ursina accepts gif animations although it does support video textures. Have you had a look at the Texture section in the [Entity Basics](https://www.ursinaengine.org/entity_basics.html)? – Jan Wilamowski Jun 28 '21 at 01:43
  • @QuantumSushi I updated my answer for animated gifs. Please let me know if I misunderstood anything. – Jan Wilamowski Jul 09 '21 at 05:48
2

Sadly, I cannot seem to find a way to play gifs. I know, @Jan Wilamowski updated his answer but, in my project, that does NOT work. You CAN show static images on this screen, though, by making a quad entity with an image texture, as shown:

class yourimage(Entity):
    def __init__(self):
        super().__init__(
            parent=camera.ui,
            model='quad',
            #size, position, and rotate your image here
            texture = 'yourimage')
yourimage()
MaxFlyMan
  • 31
  • 3