Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualP0jahn

Posted 27 December 2012 - 11:45 AM

I need a method that moves one point(this-object) to the specified coordinate, that uses integers to calculate this instead of decimals.

I have tested multiple algorithm found on the net. They all work the same and look identical ingame even if their implementation differs.
The problem is, since my game use integers as coordinates and not float, which the method found on the net use, the movespeed is not always the same. I mean, sometimes, the unit "walk" the specified speed, and sometimes it walks that specified movespeed + 1, which is unacceptable(I might sound picky, but it is noticeably ingame and can have major effect on gameplay).

I tried some things like casting and rounding but they are not helping. Here is the method.

public void moveToward(int targetX, int targetY, int steps)	//TODO:
	{
	    if(posX == targetX && posY == targetY)
	    	return;
		
	    int fX = targetX - posX;
	    int fY = targetY - posY;
	    double dist = Math.sqrt( fX*fX + fY*fY );
	    double step = (steps / dist);
	    posX += fX * step;
	    posY += fY * step;
	}

#3P0jahn

Posted 27 December 2012 - 11:43 AM

I need a method that moves one point(this-object) to the specified coordinate, that uses integers to calculate this instead of decimals.

I have tested multiple algorithm found on the net. They all work the same and look identical ingame even if their implementation differs.
The problem is, since my game use integers as coordinates and not float, which the method found on the net use, the movespeed is not always the same. I mean, sometimes, the unit "walk" the specified speed, and sometimes it walks that specified movespeed + 1, which is unacceptable(I might sound picky, but it is noticeably ingame and can have major effect on gameplay).

I tried some things like casting and rounding but they are not helping. Here is the method.

public void moveToward(int targetX, int targetY, int steps) //TODO:{   if(posX == targetX && posY == targetY)    return;   int fX = targetX - posX;   int fY = targetY - posY;   double dist = Math.sqrt( fX*fX + fY*fY );   double step = (steps / dist);   //Init the new position to this-object   posX += fX * step;   posY += fY * step;}

#2P0jahn

Posted 27 December 2012 - 11:42 AM

I need a method that moves one point(this-object) to the specified coordinate, that uses integers to calculate this instead of decimals.

I have tested multiple algorithm found on the net. They all work the same and look identical ingame even if their implementation differs.
The problem is, since my game use integers as coordinates and not float, which the method found on the net use, the movespeed is not always the same. I mean, sometimes, the unit "walk" the specified speed, and sometimes it walks that specified movespeed + 1, which is unacceptable(I might sound picky, but it is noticeably ingame and can have major effect on gameplay).

I tried some things like casting and rounding but they are not helping. Here is the method.

public void moveTorward(int targetX, int targetY, int steps) //TODO:
{
   if(posX == targetX && posY == targetY)
    return;

   int fX = targetX - posX;
   int fY = targetY - posY;
   double dist = Math.sqrt( fX*fX + fY*fY );
   double step = (steps / dist);

   //Init the new position to this-object
   posX += fX * step;
   posY += fY * step;
}

#1P0jahn

Posted 27 December 2012 - 11:39 AM

I need a method that moves one point(this-object) to the specified coordinate, that uses integers to calculate this instead of decimals.

 

I have tested multiple algorithm found on the net. They all work the same and look identical ingame even if their implementation differs.

The problem is, since my game use integers as coordinates and not float, which the method found on the net use, the movespeed is not always the same. I mean, sometimes, the unit "walk" the specified speed, and sometimes it walks that specified movespeed + 1, which is unacceptable(I might sound picky, but it is noticeably ingame and can have major effect on gameplay).

 

I tried some things like casting and rounding but they are not helping. Here is the method.

 

 


public void moveTorward(int targetX, int targetY, int steps) //TODO:
{
   if(posX == targetX && posY == targetY)
    return;
 
   int fX = targetX - posX;
   int fY = targetY - posY;
   double dist = Math.sqrt( fX*fX + fY*fY );
   double step = (steps / dist);
   
   //Init the new position to this-object
   posX += fX * step;
   posY += fY * step;
}

 


PARTNERS