0

I want to create a flashlight, when you press 1 beam appears, but I want it to disappear after a second. I made it, but my code doesn't work. My code:

from ursina import *
app = Ursina()
def flashlight(): # flashlight code
    f = Entity(model='sphere', scale=4, color=color.light_gray) 
    time.sleep(1.0) #pause
    f.visible = False #disappearing

def update(): 
    if held_keys['1']:  flashlight() 
app.run()```

Tanay
  • 561
  • 1
  • 3
  • 16
robot228
  • 3
  • 1
  • @robt228 Exactly, what is the problem in your code ? To let others understand, update the post with your real problem. – Tanay Mar 12 '23 at 16:43

1 Answers1

0

To make the Entity appear and disappear after 1 second, you can use Ursina' invoke function. Here is its implementation in your code:

from ursina import *
app = Ursina()
def test_func(e):
    e.visible = False
def flashlight(): # flashlight code
    f = Entity(model='sphere', scale=4, color=color.azure) 
    invoke(test_func, f, delay=.2)



def update(): 
    if held_keys['1']:  flashlight()

EditorCamera()
app.run()
Tanay
  • 561
  • 1
  • 3
  • 16
  • Thank you, and Can you advise how to make the flashlight effect? to be translucent – robot228 Mar 12 '23 at 17:24
  • @robot228 To make the flashlight effect translucent, you can change the `alpha` value of it's color. You can paste this code before the invoke function `f.color = color.rgba(255, 255, 255, 10)` – Tanay Mar 13 '23 at 03:09