ciauz a tutti

ho un problema un pochetto urgente!

ho un player che faccio muovere in una stanza.

Il player si muove al clic del mouse e segue il punto in cui si è cliccato con il mouse.

FIN QUI FUNZIONA TUTTO!

IL CODICE:

onClipEvent(load){
_x=0;
_y=0;
_rotation=0;


}
onClipEvent(mouseDown){

angle = (Math.atan2(_root._ymouse-_y,_root._xmouse-_x)*180/Math.PI)+90;
_rotation = angle;

targetx=_root._xmouse;
targety=_root._ymouse;

}
onClipEvent(enterFrame){

_x+=(targetx-_x)/mySpeed;
_y+=(targety-_y)/mySpeed;
}

HO TROVATO QUESTO CODICE, FRA L'ALTRO CHIARO E SEMPLICE, SU UN TUTORIAL FLAHS.

IL MIO PROBLEMA:

il mio problema è che non riesco a far fermare il mio omino quando sbatte nei muri, e farlo in seguito ripartire quando clicco con il mouse.

DOPO MILLE RICERCHE, ho trovato questo codice...ma funziona solo a metà perchè mi rallenta l'omino vicino al muro, ma dopo qualche tentativo riesce a passare oltre....

onClipEvent (enterFrame) {
with (_root.player) {

// Controls Player Speed
_root.player.mySpeed = 16;

// Controls how far the Player bounces off the wall after impact
myBounce = 16;



// detect if edges of the player is colliding with the Maze Walls
if (walls.hitTest(getBounds(_root).xMax, _y, true)) {

_x -= myBounce;

}
if (walls.hitTest(getBounds(_root).xMin, _y, true)) {
_x += myBounce;

}
if (walls.hitTest(_x, getBounds(_root).yMax, true)) {
_y -= myBounce;

}
if (walls.hitTest(_x, getBounds(_root).yMin, true)) {
_y += myBounce;

}

}
}

CREDO CHE LA SOLUZIONE SIA RIUSCIRE A FERMARE LA VELOCITà APPANA TOCCA IL MURO E FARLA RIPARTIRE SUBITO DOPO UN NUOVO CLIC DEL MOUSE.

QUALCUNO PUò AIUTARMI?

CIAO E GRAZIE IN ANTICIPO