How can i set it so a unit only moves in 4 direction so only north,east,south,west and not 360 degrees. its for a snake game. the thingies that follow you.
hope you understand and hope this is the right subcatogorie
I have recently implemented such a system. I imagine my design requirements aren't are precise as yours are assuming your snake works as per Tron/Nokia et al. However, it'll definitely help as a basis and I think I can see the other bits and pieces you'll need.
Here are my thoughts/alternatives at a high level of abstraction. They are all based on denying the player the ability to issue normal movement orders to a unit while capturing the player's intent when/where they click or when/where they launch an ability.
1) Define 4 points at the cardinal compass points on your map, OUTSIDE the playable area.(This approach turns out to be impossible if your playable area approachs the actual maximum map size because of the trigonometry involved).
Issue movement orders via triggers such that the destination is given to a point calculated by taking the X,Y of the unit's current location which you then offset by N based upon the distance between your unit's current position and the relevent compass point. You'll perhaps need to do some trigonometry to convert the hypotenuse (which is the distance you'll get) to one of the sides depening on what it is you need to achieve.
2) Capture a player's mouse clicks for movement orders (but prevent the unit from using them directly) and interpret them into whatever is meaningful for your game eg. take the vector and split it into two seperate move orders queued up, X then Y maybe, or vice versa depending on other aspects of your design. You might even wish the player to get an error if they give a diagonal and only accpet [0,Y] / [X,0] vectors or fudge small diagonals into straight lines.
3) Use a really granular region grid and implement logic similar to either of the above using regions. You will hit hard limits of coding efficiency, execution efficiency and algorithmic neatness though because region groups aren't implemented (you'd have to build them youself using arrays).
Whatever your approach, be aware of the following:
1) Combat may pervert the path a unit takes if you don't handle/prevent this eventuality.
2) Bloackages may pervert the path a unit takes if you don't handle/prevent this eventuality.
Good luck!
How can i set it so a unit only moves in 4 direction so only north,east,south,west and not 360 degrees. its for a snake game. the thingies that follow you.
hope you understand and hope this is the right subcatogorie
Thommiej
@thommiej: Go
The previous post is a bit tl;dr, so I'm just going to ask if your snake game works off the keyboard or the mouse, and in what manner?