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?
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).
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
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.
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
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.
[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)
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.