[Solved] Setting mice position?

Hi I’m making a game with multiple mice and I’m using the mice to control 4 players.

The problem I’m running into involves collisions. When the players collide, I set their position to move farther apart. However, the mouse control overrides this and they’re right back on top of each other.

Is there any way I can set the mouse position or is there soem sort of boolean work around?

Any help would be awesome.

Thanks.

Hmm… Honestly, I didn’t really get the question. How could controls override collisions?
Normally, the player FIRST sets position of his actor by pressing keyboard buttons (or somehow else), and THEN the collision traverser with collision handler checks for collisions, and corrects the position of the actor in accordance with physics rules (CollisionHandlerPusher is exactly for this).

I’ll include some code this time.

def update(self, task):
        # check for movement on all the mice
        for i in range(self.miceNum):
            # if there has been movement then get the movement
            if base.pointerWatcherNodes[i+1].hasMouse():                # +1 because of the virtual mouse               
                mX = base.pointerWatcherNodes[i+1].getMouseX()          # +1 because of the virtual mouse                
                mY = base.pointerWatcherNodes[i+1].getMouseY()          # +1 because of the virtual mouse       
            else:
                mX = 0
                mY = 0
            self.movePlayer(i+1, mX, mY)
        return Task.cont

Moveplayer simply does a setpos with scaling.

I know the collision part is being called because of the print statement

def pl1Into2v2(self, obj):
        self.enableMouse1 = False
        self.enableMouse2 = False
        if(math.fabs(self.playerMod1.getY() - self.playerMod2.getY()) < 15):
            if(self.playerMod1.getX() < self.playerMod2.getX()):
                self.playerMod1.setX(self.playerMod1.getX()-5)
                self.playerMod2.setX(self.playerMod2.getX()+5)
            else:
                self.playerMod1.setX(self.playerMod1.getX()+5)
                self.playerMod2.setX(self.playerMod2.getX()-5)
        else:
            if(self.playerMod1.getY() < self.playerMod2.getY()):
                self.playerMod1.setY(self.playerMod1.getY()-5)
                self.playerMod2.setY(self.playerMod2.getY()+5)
            else:
                self.playerMod1.setY(self.playerMod1.getY()+5)
                self.playerMod2.setY(self.playerMod2.getY()-5)
        print "pl1 into ply2"

For clarity’s sake, the second chunk of code simply moves the players apart.

Also, if someone has a better algorithm for moving apart than the one I have there, I’m sort of new to Python so that’s the best I could come up with.

Perhaps you’re looking for base.win.movePointer(i+1, x, y)?

Note that many HCI specialists feel that moving the mouse pointer in this way violates user expectations. In fact, OS X specifically forbids this action unless you first put the mouse in a special mode, which also makes the mouse pointer invisible.

David

It’s ok. I’m not looking to make anything professional.

Thanks. I’ll try it out now. Tested and not the results I expected

It appears to not be working. The players seem to move off the screen all the time and they seem to be continuously colliding.

Here’s the updated code.

def update(self, task):
        # check for movement on all the mice
        for i in range(self.miceNum):
            # if there has been movement then get the movement
            if base.pointerWatcherNodes[i+1].hasMouse():
                mX = base.pointerWatcherNodes[i+1].getMouseX()
                mY = base.pointerWatcherNodes[i+1].getMouseY()
                base.win.movePointer(i+1, mX, mY)
            else:
                mX = 0
                mY = 0
            self.movePlayer(i+1, mX, mY)
        return Task.cont
def pl1Into2v2(self, obj):
        mX1 = self.playerMod1.getX()
        mY1 = self.playerMod1.getY()
        mX2 = self.playerMod2.getX()
        mY2 = self.playerMod2.getY()
        if(math.fabs(self.playerMod1.getY() - self.playerMod2.getY()) < 15):
            if(self.playerMod1.getX() < self.playerMod2.getX()):
                base.win.movePointer(1, mX1-5, mY1)
                base.win.movePointer(2, mX2+5, mY2)
            else:
                base.win.movePointer(1, mX1+5, mY1)
                base.win.movePointer(2, mX2-5, mY2)
        else:
            if(self.playerMod1.getY() < self.playerMod2.getY()):
                base.win.movePointer(1, mX1, mY1-5)
                base.win.movePointer(2, mX2, mY2+5)
            else:
                base.win.movePointer(1, mX1, mY1+5)
                base.win.movePointer(2, mX2, mY2-5)
        print "pl1 into ply2"

You’re not using the same units. base.win.movePointer() expects to receive a mouse position in pixels, but mouseWatcher.getX(),getY() returns a mouse position in normalized screen units, which is to say, in the range -1…1.

I’m guessing you didn’t realize the nature of mouseWatcher.getX(),getY(), since you seem to be assuming it will operate in pixels–you’re checking for a proximity of 15, for instance, which will always be true with screen coordinates.

Instead of using the mouseWatcher, use base.win.getPointer(i+1).getX() and base.win.getPointer(i+1).getY(). This will return values in pixels.

David

[edit] Ahh, it seems that Drwr has it. Nevermind. ^^; [/edit]

Hmm… It looks as though at the moment you’re getting the mouse coordinates of a given pointer, and then immediately setting the same pointer’s coordinates to that same position.

Instead, surely you should be setting the mouse coordinates in the collision method, when the player’s position has been changed by something other than the mouse pointer?

(By the way, why are you operating on pointer i+1, and not i?)

I use i+1 because there’s a virtual mouse or something. Iunno I’m still in school and that’s what the teachers say at least.

The basics (without collisions) worked using i+1 so I stuck with it.

By the way, David appears to be right because they’ve stopped leaping all over the place.

A few print statements revealed coordinates of something along the range of 16,000 which caused the jumping. So it all works very well now thanks (except they move in the wrong direction… hmm)

Also, should I ignore what you said?

Well, if it works, then it’s probably not worth much worry, I don’t think.

It does seem to me that setting the mouse position should, if anywhere, be in the collision method - I’m presuming that the position acquired is goping to be, effectively, the position that you’re setting the mouse to, so doing it in the movement method doesn’t seem to make sense. It might make sense, however, in the collision method, in order to update the mouse position with the results of the collision response.

However, I may well be missing something. :confused:

That said, I’m glad that you have it working. :slight_smile:

[edit]

Fair enough, and thanks. :slight_smile:

Well, it seems that everything’s working now.

I wish there was some sort of way I could like give reputation or something cause everyone in this thread was a life saver.