#### Archived

This topic is now archived and is closed to further replies.

# Turning the Robot

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

## Recommended Posts

I''m interested in seeing how other people are handling their bot, particularly in terms of movement. Hopefully I can get some ideas regarding my current method of making my bot turn, or maybe give others some ideas. In my bot, I store my current direction as a float (MyDirection). Since it is impossible(?) to figure out the "standard" directions (0 degrees on top, 90 degrees to the right or left, then 180, etc...) I simply assign what ever direction my bot is facing at the beginning as 0 degrees. Instead of using the built in g_pCore->Turn functions, I coded my own. Well, I still use the Turn() functions, but when I call my version of it, it automatically updates my direction (degrees) by an amount, depending on the speed (it''s easy to calculate; ie: TURN_FAST = 180 units per game second * .02222 (amount of time per update) and you get a delta of 4 degrees per update) My function looks a little bit like this:
void Flint::TurnRight(int Speed)
{
g_pCore->TurnRight(Speed);
MyDirection += DegreesPerUpdate;

//bounds checking on the amount of degrees (0 to 360)

if (MyDirection >= 360.0f)
{
MyDirection = MyDirection - 360.0f;
}
};
Whenever I want to avoid something (if by turning), I store my target direction (the direction I want to end up in after the turn) I then set the State of my bot to TURN (an enumerated type) Every update, my state selector function is called (is this what is considered a finite state machine?), it looks for the TURN case, and executes my TurnToBearing() function. Depending on whether my current direction is higher or lower than my target direction, I will call g_pCore->Turn() until I reach the desired bearing. Once that''s done, I set the state to MOVE again. So basically, my state selector keeps jumping to the TURN case, until the desired direction is reached. Any thoughts on my method? Anyone else do something different? Yes, it is a contest, but since there are no prizes ATM, I think it would be fun to see what everyone is thinking, and share your own. Peon

##### Share on other sites
Sounds similar to mine. I have functions to return a specified number of degrees.
ie. Rotate(-90.0f);
You didn''t reverse engineer mine did you?
I made big mistake releasing mine as a debug because it''s trivial to view my code now... Have a look at it if you can understand any of it

##### Share on other sites
Lol, well, I''d probably take a look at the code if I knew how, but I don''t, so you''re safe Actually, I don''t care much about putting my source code up so far, if anyone''s interested. It doesn''t fire or anything yet, but it might give (complete newbies) some ideas

##### Share on other sites
The first thing my bot does is find a wall, which is no problem . Then using the direction to that wall I set my angle, so the bot is axis aligned. From this you can set the position in one dimension too. Then it''s a case of pinning down the position exactly from another wall.

Of course you actually need 3 walls to get an exact view of the arena(as 2 wont tell you which way the arena is situated(240*320 or 320*240).

This way seems to work fine for me. As for your other ways of doing things, mine works pretty much the same.

##### Share on other sites
Keep turning and scanning objects. At the turn you see the most objects run forward. I''m dumb

.lick

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631710
• Total Posts
3001846
×