0

I want to create a class that create an Entity when is called. In this class i have an update functioun where i traied to animate the entity, but the self.animate_position_x doesn't work and i get the error: "duration" is not defined.My code is:

class enemy(Entity):
    def __init__(self,x,y):
        super().__init__()
        self.model = 'quad'
        self.color = color.green
        self.collider = 'box'
        self.scale = (1,2)
        self.position = (x,y)
        self.posx = x
    def update(self):
        self.animate_x = (12, duration == 1)
        touch = self.intersects(ignore =(ground,player,))
        dist = distance(self,player)
        if touch.hit:
            destroy(self,delay = 0.05)

How can i animate in a class? P.S I use Ursina engine

Serbannn
  • 1
  • 1

1 Answers1

0

First of all you will need to fix some syntax problems (duration == 1 should be duration = 1, but you only need to put 1.

Then, everything should work. I just fixed some animation problems and then this is all done.

from ursina import *
from first_person_controller import FirstPersonController


app = Ursina()

class enemy(Entity):
    def __init__(self,x,y):
        super().__init__()
        self.model = 'quad'
        self.color = color.green
        self.collider = 'box'
        self.scale = (1,2)
        self.position = (x,y)
        self.posx = x
        
    def update(self):
        self.animate_x(1, curve=curve.in_expo)
        touch = self.intersects(ignore =(player,ground,))
        dist = distance(self,player)
        if touch.hit:
            destroy(self,delay = 0.05)

player = FirstPersonController(model = 'sphere',
                               origin = (0, -.5, 0),
                               collider = 'box',
                               )

ground = Entity(model='plane', texture='grass', collider = 'box', scale=10)


enemy(0,0)

app.run()
Lixt
  • 201
  • 4
  • 19