Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#Actualtom_mai78101

Posted 13 January 2012 - 01:33 AM

I have a dot in a blank screen. I have calculated the dot's coordinates (relative location from source component) and the mouse coordinates (after the user clicks on the screen). The constant speed of the dot is fixed at 1 pixels per tick, 60 ticks per second.

Now, there are two points in the screen. You can imagine a invisible line connecting the two points, and the dot traverses on this imaginary line from its source coordinates to the target coordinates.

What math should I use to move the dot along the line in a more linear way?

I have here a crude path movement for the dot, now basked in your glorifying eyes:

public void tick(MouseInputHandler input)
{
  target = input.mousePosition;
  if (target == null)
   return;
  int direction = 0;
  if (position.x > target.x)
   direction = -1;
  else
   direction = 1;
  if (position.x == target.x)
   direction = 0;

  position.x += direction;

  if (position.y > target.y)
   direction = -1;
  else
   direction = 1;
  if (position.y == target.y)
   direction = 0;
  position.y += direction;
}

If possible, where can I improve? And where can I learn more about path movement algorithms? Thanks in advance.

#3tom_mai78101

Posted 13 January 2012 - 01:30 AM

I have a dot in a blank screen. I have calculated the dot's coordinates (relative location from source component) and the mouse coordinates (after the user clicks on the screen). The constant speed of the dot is fixed at 1 pixels per tick, 60 ticks per second.

Now, there are two points in the screen. You can imagine a invisible line connecting the two points, and the dot traverses on this imaginary line from its source coordinates to the target coordinates.

What math should I use to move the dot along the line in a more linear way?

I have here a crude path movement for the dot, now basked in your glorifying eyes:

public void tick(MouseInputHandler input)
{
  target = input.mousePosition;
  if (target == null)
   return;
  int direction = 0;
  if (position.x > target.x)
   direction = -1;
  else
   direction = 1;
  if (position.x == target.x)
   direction = 0;

  position.x += direction;

  if (position.y > target.y)
   direction = -1;
  else
   direction = 1;
  if (position.y == target.y)
   direction = 0;
  position.y += direction;
}

If possible, where can I improve? And where can I learn more about path movement algorithms? Thanks in advance.

#2tom_mai78101

Posted 13 January 2012 - 01:30 AM

I have a dot in a blank screen. I have calculated the dot's coordinates (relative location from source component) and the mouse coordinates (after the user clicks on the screen). The constant speed of the dot is fixed at 1 pixels per tick, 60 ticks per second.

Now, there are two points in the screen. You can imagine a invisible line connecting the two points, and the dot traverses on this imaginary line from its source coordinates to the target coordinates.

What math should I use to move the dot along the line in a more linear way?

I have here a crude path movement for the dot, now basked in your glorifying eyes:

[source lang="java"]public void tick(MouseInputHandler input){  target = input.mousePosition;  if (target == null)   return;  int direction = 0;  if (position.x > target.x)   direction = -1;  else   direction = 1;  if (position.x == target.x)   direction = 0;  position.x += direction;  if (position.y > target.y)   direction = -1;  else   direction = 1;  if (position.y == target.y)   direction = 0;  position.y += direction;}[/source]

If possible, where can I improve? And where can I learn more about path movement algorithms? Thanks in advance.

#1tom_mai78101

Posted 13 January 2012 - 01:27 AM

I have a dot in a blank screen. I have calculated the dot's coordinates (relative location from source component) and the mouse coordinates (after the user clicks on the screen). The constant speed of the dot is fixed at 1 pixels per tick, 60 ticks per second.

Now, there are two points in the screen. You can imagine a invisible line connecting the two points, and the dot traverses on this imaginary line from its source coordinates to the target coordinates.

What math should I use to move the dot along the line in a more linear way?

I have here a crude path movement for the dot, now basked in your glorifying eyes:

public void tick(MouseInputHandler input)
{
  target = input.mousePosition;
  if (target == null)
   return;
  int direction = 0;
  if (position.x > target.x)
   direction = -1;
  else
   direction = 1;
  if (position.x == target.x)
   direction = 0;
 
  position.x += direction;
 
  if (position.y > target.y)
   direction = -1;
  else
   direction = 1;
  if (position.y == target.y)
   direction = 0;
  position.y += direction;
}

If possible, where can I improve? And where can I learn more about path movement algorithms? Thanks in advance.

PARTNERS