I could not figure out how to dig on any ground i walk on

How would i to dig on any of the ground i walk on?
Here is link to thread.https://blenderartists.org/forum/showthread.php?410708-spawn-down-problem-again

Use a shovel

good idea, smartass.

i think you have to explain better what you want to do, it’s too much generic

I would like it when i end the next piece of ground in the +y direction.That there would be added underneath it two
more pieces of ground underneath each other.

just use the use the position from the object you want the new object be below as reference.

objectA is the object you want the new object to be below
objectB is the object you want to be below objectA

“howfar” is the distance

howfar = -5

objectB = scene.addObject("Cube",objectA,0)

objectB.worldPosition.z  + howfar

I will see if i can figure that out.

I am stumped at where to put it?I put it by the doted line in this code.

# endless runner by cotax v1.2

# V1.2 changes:
# max_distance changed into spawn_distance
# added_before changed into a list and has its own distance check called remove_distance
# added 2 more ground planes and parented objects to it, it now uses random.choice to select one
# added a tiny bit of comments at the things you can change
# player jump height changed from and set to tap mode (no flying anymore, but unlimited jumps)
# due to the changes of the distance check, the ground plane will not be removed if you jump at the end
# instead of max. 2 ground planes you now have a max. of 3 ground planes on screen 

import random

def create(cont):
    own     = cont.owner
    scene   = own.scene
    if not 'last_added' in own:
        own['added_before'] = []
        own['last_added']   = None
        own['ground_objects'] = [obj for obj in scene.objectsInactive if 'ground' in obj]

    player              = scene.objects['player']
    ground_plane_size   = 30.0 # Y direction / used as an offset
    ground_plane_down   = -3.0 
    spawn_distance      = ground_plane_size /2 # min: of choice, max: ground_plane_size (from origin)
    remove_distance     = ground_plane_size  # min: ground_plane_size , max: of choice (from origin)
    spawn_distance2      = ground_plane_down /8 #
    remove_distance2     = ground_plane_down 
    # origin = the orange dot you see when you have an object selected, move object in edit mode(tab)
    # to change the origins position, or select all and hit shift+s then 3d cursor to selected and in 
    # object mode select the object hit ctrl+shift+alt+c and place it at the 3d cursor to center it.

    # it is used at to check distances, so if things go wrong check the origin/distances 
    # i suggest to keep the origin at the center and at the top of the ground plane
    if own['last_added']:

        distance_to_last_added  = player.getDistanceTo(own['last_added'])
        random_height           = random.choice([-1, 0, 1]) # ground plane spawn heights
        if distance_to_last_added < spawn_distance: 
            own.worldPosition.z -= ground_plane_size
            own.worldPosition.z  +  ground_plane_down-------------------------------------------------- 

    if own['added_before']:
        for obj in own['added_before']: 
            distance_to_added_before = player.getDistanceTo(obj)
            if distance_to_added_before > remove_distance: 

def add_object(cont):  
    own     = cont.owner
    scene   = own.scene
    added_object = scene.addObject(random.choice(own['ground_objects']), own, 0)
    if own['last_added']:    
    own['last_added'] = added_object

this is not an easy thing to do. im a fairly experienced python coder, and im not quite sure how to make a stable setup. it would require a very optimized level setup. i recommend getting very familiar with python before attempting something of this complexity.

why would you want to dig? maybe theres a better way to implement the mechanic you are looking for.

Why i want digging is so that the player can find valuable resources and tunnels with enemies in them.

What I would do is detect the position of the shovel or whatever is digging when it touches the ground. then I would get the vertex points around that area and translate them downward a few units. Then recalculate the normals of the mesh and you’re good to go.

I like the method i am using because their is no need to move vertex.Although i have not figured it out completely.

if you translate the vertices, does the update collision mesh work? i have never tried.

Yes, there is a function you can call for that.

I really need help with this.

i guess that to dig (rather than just walk on something) is better use something similar to cubes that fill all 3 dimensions.
(i know cubes risk to have too many faces … but)

try this, it use the same code of “infinite runner” , a bit modified.
the principle is anyway the same , each piece/cube/tile, “consume” a certain space .
the space(cell) is stored in a grid (dictionary)
the cell change some value , but is ever in the same position and is never removed
when the player go too far the cubes are removed, but the cell still

due to this (add/remove cubes) the physic of the game is “unstable” , so the npcs can “fall” …not tested but sound very probable …


TESTVC2.blend (145 KB)

How would i have it so it would build behind?Keeping the space around the player 4 block longs and one block high.Would it be easy to make enemies that dig and follow the player the way it is?

I figured out how to make enemies dig in the blend you provided.Although with logic bricks.

what count is the number of (real)cubes in the scene , i got that more or less is around to 1500 , with this number the rasterizer starts to be heavy (also if the ms are not much reliable) ,
bullet turn around to 2ms (with some npc can become 3/4ms)
so we say that 1500 is the limit.

if you had 2 dimension are 3838 , so 19 cubes “around”
if the cubes are 1
11, the range is 19 meters around the player
if the cubes are 2 meters are 38 meters
if are cubes 4
4*4 are are 76 meters.

adding the third dimension the range become much more little.(4/5 cubes)
limits the axis Z , mean have more cubes in the other directions.

but mean also the you cannot dig much …

I figured out how to make enemies dig in the blend you provided.Although with logic bricks.

that is strange i have not minded that the npcs can dig , i have not made a easy access to the “cubemanger”
probably you just ends the cubes directly(?) this can work in some cases , but in other cases can do strange stuff.
because the cubemanger think that the cube already exist and so not add , or something like this(nothing of dangerous but)

i have to do some save-load system , is necessary .
what you think about the addcube operation? is enought , or should be used some other way ?

I do end the cubes with collission sensor.The enemies always emit cubes with a certain property which are invisible.And are dynamic and ghost.And they end quickly.The add cube system is great.It already remembers the cubes i dig out.
The ability for it randomly spawn enemies in place of some of cubes would be great.Could you make it so the cubes have collision under the player and the rest of them are no collision cubes?That would make the framerate better.It always does.I think your system better.I have tested other people’s systems.