That's a hard problem since you have no direct control over the mouse, other than hiding and showing it.
I probably wouldn't hide the mouse in this case, since mouse movement and player movement aren't 1 to 1. That way people can see if they're moving the mouse out of the game area. It's uglier, but it might be necessary. That said, if you want to tie the player directly to the mouse, I would look into line-circle intersection algorithms, or swept-circle to circle collision detection. Every update, you draw a line from the previous player position to the new position. If it intersects a mushroom, store the previous position, find the first point of intersection, and stick the player there. Next update, go from the stored previous position to the current mouse position, check for intersection, etc. etc. until there's no intersection, then stick the player on the cursor again. --- Martin Scott Goldberg <[EMAIL PROTECTED]> wrote: > Hey all, back again. > > I'm doing a remake of centipede, and am looking for > suggestion on the > mouse tracking routine (in as3). > > The enivronment: The player is of course at the > bottom of the screen, and > can only move up a specific distance. He may be > blocked by mushrooms in > this area as well. > > Speficially, I have two ways of player motion with > the mouse I've tried > and neither one is 100% accurate: > > 1) Set the player graphic equal to the mouse > reading: > > > thePlayer.x = this.mouseX; > thePlayer.y = this.mouseY; > > This is the same as thePlayer.startDrag(), just > chose to go this route. > Player tracks the mouse motion perfectly this way > of course. > Then the code checks for mushroom collision, > which stops the player > motion. > > The issue I'm having is, whenever the player > comes in contact with > a mushroom in the lower player movement area, > it's supposed to stop > dead, forcing the player to move around it. With > this method though, > it stops for a second, but then skips over the > mushroom once the mouse > moves past it. Likewise, it creates a "sticking" > at the upper, lower > right, and left boundries since it sits there > until the mouse enters > back in to the "player zone". > > 2) Record previous mouse motion in x and y, and > compare it to current. If > its moving right, move the player right 1 place. > Mouse moving left, > moving player left one space, etc.: > > if (previousMouseX < this.mouseX) > { > thePlayer.x += playerSpeed; > } > else > { > thePlayer.x -= playerSpeed; > } > > And similar for y direction. Now, this code > works perfect with the > mushroom obstruction dectection. But I'm having > the opposite issue > from the first code: The mouse tracking makes it > harder to move in a > straight line, and the mouse moves out of the > stage very quickly, > being out of proportion to the rate of the player > motion. Upping the > playerSpeed of course doesn't help, that just > makes the player graphic > jump around to quick. > > If anyone on this list that's played around with > these types of issues > before has an suggestions, I'd greatly appreciate > it. > > > > Marty > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the > archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > ____________________________________________________________________________________Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. http://mobile.yahoo.com/go?refer=1GNXIC _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com