Jump to content
  • Advertisement
Sign in to follow this  

Rotation issues

This topic is 3277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm quite new to flash, and i was trying to make an object move to where i click. not just moving there in a straight line, but by turning its direction. i have this working quite well, but it still has 2 flaws. one small flaw, that if you make a certain (large) angle between the object's direction and the direction it needs to move to, it will turn the other way around (instead of the other, shorter way). the second flaw is that, when you click nearly horizontal left of the object, it starts moving in the shape of an "8" in the opposite direction. this is the code i use, i hope something could help me with this. Thanks for reading, Jurrien.
onClipEvent (load) {
	xto = _x+1;
	yto = _y+1;
	dir = 1;
	dirto = 0;
	rotspeed = 10;
	speed = 10;
	dis = Math.sqrt(((xto-_x)*(xto-_x))+((yto-_y)*(yto-_y)))
onClipEvent (mouseDown) {
	xto = _root._xmouse;
	yto = _root._ymouse;
onClipEvent (enterFrame) {
	dis = Math.sqrt(((xto-_x)*(xto-_x))+((yto-_y)*(yto-_y)));
	if (dis>10) {
		dirto = Math.atan2(yto-_y, xto-_x)/(Math.PI/180);
		if (dir>180 and dirto<dir-180) {
			dirto -= 360;
		if (dir<180 and dirto>dir+180) {
			dirto += 360;
		if (dir>dirto) {
			dir -= Math.min(dir - dirto, rotspeed);
		if (dir<dirto) {
			dir += Math.min(dirto - dir, rotspeed);
		_rotation = dir;
		_x += Math.cos(dir*Math.PI/180)*speed;
		_y += Math.sin(dir*Math.PI/180)*speed;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!