Making a sprite (mc) face the direction it is moving

Enjoy the fish:

[color=#0000ff]http://www.tankbangers.com/LAYOUT1.swf[/color]

peruse the FLA:

[color=#0000ff]http://www.tankbangers.com/LAYOUT1.fla[/color]

Notice how the fish flee from an advancing cursor (much like real fish). I have tried using atan2 and other tricks to get the fish to face AWAY from the pursuing mouse cursor, but what happens is that when the fish are moving from _Xpositive to _Xnegative (right to left) they appear to be swimming upside down. I have abandoned atan2 for the time being. Is there a way to get a movie clip to reflect along the y axis depending on which side of the mouse cursor it is on? That might be one solution.

Here is something else that would earn partial credit:
If you can corner one of the fish you will notice that when you click on it, you can cause it some distress. (meanie!) I would like to get the fish to ‘gulp’ some bubbles, like in this clip,
[color=#0000ff]http://www.tankbangers.com/LAYOUT1b.swf[/color]
[color=#0000ff]http://www.tankbangers.com/LAYOUT1b.fla[/color]
but without destroying the random movement and cursor avoidance behaviour of the first clip. Can you figure it out?! cuz I can’t

lmao thats good i like that!! lol ill hav a look! :smiley:

Prophet.

do you want them to face away in 360 degs or just face away as in left or right?

if(xdiff>0){
	var dir=-100
}
else{
	var dir=100
}
this._xscale = dir

in your avoid mouse prototype will do the 2 way thing…

ill give the 360 deg thing more thought…

Prophet.

ok - i’ll give what you’ve written here so far a run-through when i get home.

hehe - thanks Prophet - that looks pretty cool now. I wish I had a little more money so I could hire someone like you :confused:
I extended the constraining box so that the fish have a fighting chance, and now, to try and make them draggable and maybe add a little score tag in the corner (10 pts every time you manage to ‘grab’ a fish)

I had to do a similar thing for a game I’m working on.

for the most part, it was the same as the snippet prophet posted, but to get the angle working as well, I had to use Math.atan2 at the same time.

putting both methods together should sort you out. It will require some testing/tweaking though.

I’d have a look through your code, but I’m at work atm, so I can’t really be much more help.

interesting- ok, i’ll do some more experimenting tonight

hi. I’ve figured out how to do it. here it is:

thanks, cyberathlete, but I need the clip to avoid the mouse, not follow it. There are quite a few Scottish flashers on this forum - coincidence? :slight_smile:

It’s no coincidence, all scots are pro. :wink:

I amn’t sure how to actionscript code to make something avoid the mouse. if someone tells me how, i can easily edit the code to include this.

ah, ok i got the fla off your site. i’m looking at it now.

hmmm… i just cut an pasted the code from cyberathletes into calydons…

dont look too pretty… just looks wrong… maybe i have an idea though! :wink:

Prophet.

EDIT:- LOL how about adding

		if(dir>0){
			this._rotation = ydiff*-0.06
		}
		else{
			this._rotation = ydiff*0.06
		}

just beneath the code i suggested earlier!! lol pretty neat…

watu think??

yeah i tried cutting and copying too. it went doolally.

Been too busy to reply to this promptly. Just wanted to thank Prophet and Cyberathlete for their help - as a gift to the community I’m making the FLA available for download if you want to try something similar.

http://www.tankbangers.com/LAYOUT_init2b.fla

Oh, and Prophet - I thought your angle effect was a bit too subtle so I changed the ydiff*-0.06 to ydiff*-0.15. Thanks again!

cool!
dont thank me, it was a lot of fun2do!!! :smiley:

Prophet.

glad you got it resolved :slight_smile: