Target specific axis on raycast for " if " statement?

Hi,

I made a little script that adds blocks ontop of eachother with a ray that randomly goes over a grid.
The ray sensor “hitground” is targetting “grass” blocks and is moved a random amount between -1 and 1 every tick.

How can I specifically target the Z axis of the hitPosition to check if the Z axis of the hitPosition isn’t higher then a certain number? ( I want to use this so I can add rock blocks if the Z axis is higher then let’s say 5 )

Here’s the code for adding in blocks:

if own['randnum'] > -5000:        own['randnum'] -=1
        pos = [own['x'],own['y'],own['z']]
        holder.worldPosition = pos
        if hitground.positive:
            pos = [own['x'],own['y'],own['z']]
            if hitground.hitPosition <= [50,50,5]:
                object = scene.addObject(randob[0],'grid')
                object.worldPosition = hitground.hitPosition
        own['x'] +=randint(-1,1)
        own['y'] +=randint(-1,1)
        if own['x'] > 50:
            own['x'] = 50
        if own['y'] > 50:
            own['y'] = 50
        if own['x'] < 0:
            own['x'] = 0
        if own['y'] < 0:
            own['y'] = 0

The last piece of code specifies that the sensor won’t go over an X and Y of 50.

I tought of something like:

if hitground.hitPosition <= [50,50,5]:

But that won’t take Z axis in account.

Any ideas?

What do you think - When is a list of numbers equal or less a list of numbers?

I could not find any details on list, so I did some tests. The list compare (a < b) compares the list item by item until it finds a difference. This means the order is determined by the contained elements.

[1,2,3] < [1,2,4]
because 3<4

[1,2,3] < [1,2,3,4]
because the first 3 elements are equal, but the right list is longer.

This makes not much sense when working with coordinates, especially as you are looking for the z-coordinate only. You better go for:


if hitground.hitPosition[2] &lt; 5:

Thanks! I got it to work after a few hours of fiddling :stuck_out_tongue: