0

So I wanted to something like mining game in ursina engine. I wanted that if you mine a block other blocks will appear under that block and on other sides of this block creating a mining effect. I tried raycasting but i can't properly set it and it seems that i even don't understand raycasting. My inspiration is Mining Simulator game from roblox(maybe that help to understand what am i trying to achive. Here is a link to this game: https://www.roblox.com/games/1417427737/Mining-Simulator). Basicly i want to check if there isnt a block beside and if there is not a block beside then dont generate a block. Here's my code:

from ursina import *
from ursina.prefabs.first_person_controller import FirstPersonController
app = Ursina(borderless=False)
g = Entity(model='plane', scale = (16,1,16), collider='box')
Sky()
player = FirstPersonController(jump_height=3)
class Voxel(Button):
    global depth
    def __init__(self, position = (0,0,0)):
        super().__init__(
            parent = scene,
            position = position,
            model = 'cube',
            collider = 'box',
            rotation = (0,0,0),
            scale = (3,3,3),
            color = color.rgb(random.uniform(0,255),random.uniform(0,255),random.uniform(0,255))
            )
    def input(self, key):
        def gen_blocks():
            p = self.position
            p.y -= 3
            voxel = Voxel(position=p)
            p.y += 3
            p.z -= 3
            voxel = Voxel(position=p)
            p.z += 6
            voxel = Voxel(position=p)
            p.z -= 3
            p.x += 3
            voxel = Voxel(position=p)
            p.x -= 6
            voxel = Voxel(position=p)
        if self.hovered:
            if key == 'left mouse down':
                gen_blocks()
                destroy(self)
for z in range(8):
        for x in range(8):
            voxel = Voxel(position = (x * 3 - 8,-1,z * 3 + 9))
app.run()
Neufdi
  • 15
  • 3
  • What's your question? Please provide actual and expected behavior as well as any errors you may encounter. – Jan Wilamowski Mar 17 '22 at 02:49
  • @JanWilamowski My question is how to make a cube not appear on other cube when clicking on them. Cause if you click on cube and then click on them a bunch of times (i mean clicking if the camera is pointed at ground) and then click on a block on the beside, it will create a cube in FirstPersonController. – Neufdi Mar 17 '22 at 07:44
  • while could find that out via some complicated collision logic, it would be easier to just save the grid of existing cubes and then only add those anew which don't exist yet. – Jan Wilamowski Mar 18 '22 at 07:11
  • @JanWilamowski i don't know how to even start with doing a grid like that – Neufdi Apr 10 '22 at 20:45
  • it's a 3D array (e.g. a Numpy array) that has a True/False flag for each position. Before you create a new cube, check the grid whether it already exists. Every time you create a new cube, you update the grid. – Jan Wilamowski Apr 12 '22 at 01:37
  • @JanWilamowski I was thinking about to give every cube 3 variables x_pos, y_pos and z_pos. Then check if they are the same, if yes then destroy cube – Neufdi Apr 13 '22 at 08:09

0 Answers0