how can i pick up items in ursina?

Viewed 27

Because as I programmed it by pressing the "f" it picks it up from anywhere on the map.

I try to create an object collection system with a distance limitation, that is, you can only collect it next to the object.

This is my code:

Arma = Entity(model="revolver.glb", collider="box", position=(10, 1, 10), scale=.04, rotation=(0,0,90))




def input(key):
   if key == "f":
      destroy(Arma)
      # Pistola
      ARMA = Entity(model="revolver.glb", parent=camera.ui, scale=.04, position=(.4, -.5),
                 rotation=(5, 170, 0))
1 Answers

You must check the distance between the player and the gun :

Arma = Entity(model="revolver.glb", collider="box", position=(10, 1, 10), scale=.04, rotation=(0,0,90))
player = FirstPersonController()
def input(key):
    global Arma
    if key == "f":
        if distance(player, Arma):
            
            destroy(Arma)
            Arma = Entity(model="revolver.glb", parent=camera.ui, scale=.04, position=(.4, -.5),
                rotation=(5, 170, 0))
Related