Mouse Over doesn't work at certain angles?

The attached blend file contains a very simple game of Ludo.
I can move the blue pieces all the way round the board by clicking on them, but the red pieces refuse to move. The weird part is, if I rotate the board 180 deg I can now move some of the red pieces some way and some of the blue pieces some way.
Any ideas what I can do to make this work? :confused:

Attachments


test2.blend (729 KB)

Tryed it: after moving all blue as far as possible , the red ones could be moved …!!!

But (when not seen) I got these error message:
Traceback (most recent call last):
File “gameLogic”, line 36, in <module>
File “gameLogic”, line 33, in main
IndexError: tuple index out of range

several times.

With this changes it works !!!???


import bge

def main():
    cont = bge.logic.getCurrentController()
    mouse = bge.logic.mouse
    scene = bge.logic.getCurrentScene()
    
    objects = scene.objects    
    playerA = (objects['red.1'], objects['red.2'], objects['red.3'], objects['red.4'])
    playerB = (objects['blue.1'], objects['blue.2'], objects['blue.3'], objects['blue.4'])
    
    commonFields = ((-6.5, 1, 0), (-5.5, 1, 0), (-4.5, 1, 0), (-3.5, 1, 0), (-2.5, 1, 0), (-1.3, 1.1, 0), (-0.6, 1.8, 0), (0.6, 1.8, 0), (1.3, 1.1, 0), (2.5, 1, 0), (3.5, 1, 0), (4.5, 1, 0), (5.5, 1, 0), (6.5, 1, 0), (6.5, 0, 0), (6.5, -1, 0), (5.5, -1, 0), (4.5, -1, 0), (3.5, -1, 0), (2.5, -1, 0), (1.3, -1.1, 0), (0.6, -1.8, 0), (-0.6, -1.8, 0), (-1.3, -1.1, 0), (-2.5, -1, 0), (-3.5, -1, 0), (-4.5, -1, 0), (-5.5, -1, 0), (-6.5, -1, 0), (-6.5, 0, 0))
    lanes = {'commonFields':commonFields}

    wp = '' 
    for piece in playerA:
        if 'location' not in piece:
            piece['lane'] = 'commonFields'
            piece['location'] = 15
            wp = "playerA"
    for piece in playerB:
        if 'location' not in piece:
            piece['lane'] = 'commonFields'
            piece['location'] = 0
            wp="playerB"
            
    
    die = 1
    
    if bge.logic.KX_INPUT_JUST_ACTIVATED == mouse.events[bge.events.LEFTMOUSE]:
        piece = cont.sensors["MouseOverAny"].hitObject
        if piece in playerA or piece in playerB:
            curPos = piece['location']
            newPos = curPos + die
            print("newPos and player = ", newPos, wp)
            piece.position = lanes[piece['lane']][newPos]
            piece['location'] = newPos
    
main()  

But after a time:
File “gameLogic”, line 36, in main
IndexError: tuple index out of range
newPos and player = 4
newPos and player = 16
newPos and player = 16
newPos and player = 17
newPos and player = 17
newPos and player = 16
newPos and player = 17
newPos and player = 18
newPos and player = 18
newPos and player = 19
newPos and player = 20
newPos and player = 30
Python script error - object ‘gameLogic’, controller ‘Python’:
Traceback (most recent call last):
File “gameLogic”, line 39, in <module>
File “gameLogic”, line 36, in main
IndexError: tuple index out of range
newPos and player = 30
Python script error - object ‘gameLogic’, controller ‘Python’:
Traceback (most recent call last):
File “gameLogic”, line 39, in <module>
File “gameLogic”, line 36, in main
IndexError: tuple index out of range

Strange, wp is not printed???

The error is not strange: The code does not handle the pieces crossing the starting point (yet), so it just tries to move the piece to the next field on the board.
You set wp in the for loop, that’s why it is not available in logic part. But as I said: Never mind the game logic, I’ve got most of it figured out, just wanted to keep this as simple as possible until I get all the other issues figured out.

But I still can’t move the red pieces unless I rotate the view, not even after all the blue pieces have been moved.

What are the rules?

And there is a logic error I think … red starts at 15 and should go the other way round?
Number of fields to small? 30?

Which Blender version ? I run the latest of today …

and with this code I can move blue AND red


import bge

def main():
    cont = bge.logic.getCurrentController()
    mouse = bge.logic.mouse
    scene = bge.logic.getCurrentScene()
    
    objects = scene.objects    
    playerA = (objects['red.1'], objects['red.2'], objects['red.3'], objects['red.4'])
    playerB = (objects['blue.1'], objects['blue.2'], objects['blue.3'], objects['blue.4'])
    
    commonFields = ((-6.5, 1, 0), (-5.5, 1, 0), (-4.5, 1, 0), (-3.5, 1, 0), (-2.5, 1, 0), (-1.3, 1.1, 0), (-0.6, 1.8, 0), (0.6, 1.8, 0), (1.3, 1.1, 0), (2.5, 1, 0), (3.5, 1, 0), (4.5, 1, 0), (5.5, 1, 0), (6.5, 1, 0), (6.5, 0, 0), (6.5, -1, 0), (5.5, -1, 0), (4.5, -1, 0), (3.5, -1, 0), (2.5, -1, 0), (1.3, -1.1, 0), (0.6, -1.8, 0), (-0.6, -1.8, 0), (-1.3, -1.1, 0), (-2.5, -1, 0), (-3.5, -1, 0), (-4.5, -1, 0), (-5.5, -1, 0), (-6.5, -1, 0), (-6.5, 0, 0))
    lanes = {'commonFields':commonFields}

    wp = '' 
    for piece in playerA:
        if 'location' not in piece:
            piece['lane'] = 'commonFields'
            piece['location'] = 15
            wp = "playerA"
    for piece in playerB:
        if 'location' not in piece:
            piece['lane'] = 'commonFields'
            piece['location'] = 0
            wp="playerB"
            
    
    die = 1
    
    if bge.logic.KX_INPUT_JUST_ACTIVATED == mouse.events[bge.events.LEFTMOUSE]:
        piece = cont.sensors["MouseOverAny"].hitObject
        if piece in playerA :
            curPos = piece['location']
            newPos = curPos + die
            print("newPos and player = ", newPos,"A")
            piece.position = lanes[piece['lane']][newPos]
            piece['location'] = newPos
        elif piece in playerB:
            curPos = piece['location']
            newPos = curPos + die
            print("newPos and player = ", newPos,"B")
            piece.position = lanes[piece['lane']][newPos]
            piece['location'] = newPos            
    
main()  

Hmmm… I have downloaded Blender 2.59 and copied your code but I still get the same result: I can move the blue pieces but not the red ones :frowning:

Maybe because you use the ‘orthographic’ view OUTSIDE the camera. This gives some problems with the mouse-pointer. Instead view using ‘perspective’, or from a camera with either ‘orthographic’ or ‘perspective’. That should make it work.

I will give that a try as soon as I get home from work and post the result.

Rotory, you are my new best friend :RocknRoll:
Changing to perspective made all the difference. I will experiment with the camera views.
Thanks a lot!

–
Best regards
Stefan

Keep up the fun :slight_smile:

You can up the lens a lot to make it look orthographic, but keep the view being perspective, and so possibly be able to bypass the issue as Rotory mentioned.

@SolarLune
It’s only happening when not viewing from a camera AND in orthographic. At least, I never had the problems when using a camera in either way :slight_smile: