Author Topic: Movement on a grid  (Read 980 times)

Offline Emicarn

  • Level 5
  • *
  • Posts: 19
  • Reputation: +0/-0
    • View Profile
Movement on a grid
« on: January 12, 2011, 10:53:16 AM »
The Goal:

Given a vessel is at a specific coordinate on an X,Y grid and wants to move to a new one, each point of distance uses one point of power.   [Power is the limiting factor ultimately to what a player can do].

Player is at 1,1 and wishes to move to 100,100 which is approximate distance of 140.   With only 20 points to use to move how do you figure where they can reach?

The Problem:

A discussion elsewhere trying to figure out the formula to determine where a distance of 20 would drop you on a line from (1,1) to (100,100) brought up an interesting thought.

My idea was that all travel would be in a direct line from Point A to Point B.  A respondent mentioned that any movement on either axis might use 1 point of power.

The two methods of movement I'm not looking at is:

Method 1:   Trying to determine the distance from Point A you can travel given X power points towards Point B, compute the X,Y coordinate and present that the player.

Method 2:  Change each axis by 1 until you come up with a location using all available power that would be more of a zig zag method of movement.


any thoughts on this from a design standpoint or game play stand point?

Or maybe a method I've not considered here?

Thanks!


Which would be the most efficient way to figure travel?

Thanks!

~ Rich

http://www.sectorbattles.com [not ready for prime time]

Offline CygnusX

  • Level 24
  • *
  • Posts: 304
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Movement on a grid
« Reply #1 on: January 12, 2011, 10:58:46 AM »
I don't mean to complicate your problem, but have you considered a Hex grid layout?  This is usually considered a more 'fair' solution than a 2 axis setup.

Offline Emicarn

  • Level 5
  • *
  • Posts: 19
  • Reputation: +0/-0
    • View Profile
Re: Movement on a grid
« Reply #2 on: January 12, 2011, 11:15:35 AM »
I don't mean to complicate your problem, but have you considered a Hex grid layout?  This is usually considered a more 'fair' solution than a 2 axis setup.

You know actually I hadn't.

  And that doesn't complicate things a bit, well maybe a little since I'll need to research how to figure distances on a hex map.

Thanks!

~ Rich

http://www.sectorbattles.com [not ready for prime time]

Offline CygnusX

  • Level 24
  • *
  • Posts: 304
  • Reputation: +3/-2
    • View Profile
    • Lords of Midnight
Re: Movement on a grid
« Reply #3 on: January 12, 2011, 11:23:12 AM »
In your case, I don't think you need to figure distance.  On a hex grid, each adjacent space would be 1 move.  So, if the player has 15 movement turns, they can move 15 Hex tiles....

You would then probably want to, upon unit selection, highlight a circumference around the unit that shows how far it can travel.  A user can then pick any space in the highlighted region to move to, turns can be subtracted, etc.

Offline saljutin

  • Level 22
  • *
  • Posts: 266
  • Reputation: +6/-0
    • View Profile
Re: Movement on a grid
« Reply #4 on: January 12, 2011, 03:29:44 PM »
http://en.wikipedia.org/wiki/Polar_coordinate_system
this is solution to your problem

by using X,Y of point where u want to travel you get Xgoal, Ygoal

you get your angle "A" by using tan(A) = Ygoal / Xgoal

r - how many turns does player have

x = r*cos(A)
y = r*sin(A)

voila! :D

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Movement on a grid
« Reply #5 on: January 13, 2011, 06:00:49 AM »
For raw distance calculation almost everyone uses Pythagoras. Technicly, this is the fastest method (might be not true in interpeted language like PHP).

http://en.wikipedia.org/wiki/Pythagoras

$a=abs($x1-$x2);
$b=abs($y1-$y2);
$c=sqrt($a*$a+$b*$b);

Offline pixlepix

  • Level 12
  • *
  • Posts: 90
  • Reputation: +0/-0
    • View Profile
Re: Movement on a grid
« Reply #6 on: January 13, 2011, 03:01:34 PM »
actualy, the abs isnt needed, as any number squared will be positive.

Offline saljutin

  • Level 22
  • *
  • Posts: 266
  • Reputation: +6/-0
    • View Profile
Re: Movement on a grid
« Reply #7 on: January 15, 2011, 12:50:36 PM »
Player is at 1,1 and wishes to move to 100,100 which is approximate distance of 140.   With only 20 points to use to move how do you figure where they can reach?

so chris how will game know where to move? the thingy you presented will know HOW many points will he need to move from 1,1 to 100,100, but how do you get X and Y of that direction when he can only move for 20 points?

I am not saying my method is the best - because I know there can be some others methods to be more optimized so thats why I am asking :)

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Movement on a grid
« Reply #8 on: January 15, 2011, 01:46:24 PM »
so chris how will game know where to move? the thingy you presented will know HOW many points will he need to move from 1,1 to 100,100, but how do you get X and Y of that direction when he can only move for 20 points?
I have an annoying habit of giving the most needed answer instead of accurate answer. So, when I heard someone saying that "their friend told them about zig zag movement problem" it means that such person would greatly benefit from understanding Pythagoras theorem before moving to luxurious and sophisticated polar coordinate system :D

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal