Difference between revisions of "Oscillator Movement"
GrubbmGait (talk | contribs) m (give correct name in category) |
(use <syntaxhighlight>) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
− | |||
Oscillators usually play perpendicular to enemy bot, and avoid being hit by changing direction frequently. Oscillating movement is very easy to implement, needs only a few lines of code, and can be combined with avoiding and other tricks. | Oscillators usually play perpendicular to enemy bot, and avoid being hit by changing direction frequently. Oscillating movement is very easy to implement, needs only a few lines of code, and can be combined with avoiding and other tricks. | ||
Some disadvantages of oscillating movement are that you can get easily hit by an advanced targeting system, and that you have little control on your absolute position in the battlefield (you define the position relative to the enemy). | Some disadvantages of oscillating movement are that you can get easily hit by an advanced targeting system, and that you have little control on your absolute position in the battlefield (you define the position relative to the enemy). | ||
+ | |||
+ | == Direct == | ||
Here it goes some code similar to the one MicroAspid 1.2 was using (feel free to use it on your bots). | Here it goes some code similar to the one MicroAspid 1.2 was using (feel free to use it on your bots). | ||
− | < | + | |
+ | <syntaxhighlight> | ||
//** it is from onScannedRobot | //** it is from onScannedRobot | ||
if (getDistanceRemaining() == 0) { FORWARD = -FORWARD; setAhead(185 * FORWARD); } | if (getDistanceRemaining() == 0) { FORWARD = -FORWARD; setAhead(185 * FORWARD); } | ||
setTurnRightRadians(e.getBearingRadians() + Math.PI/2 - 0.5236 * FORWARD * (e.getDistance() > 200 ? 1 : -1)); | setTurnRightRadians(e.getBearingRadians() + Math.PI/2 - 0.5236 * FORWARD * (e.getDistance() > 200 ? 1 : -1)); | ||
− | </ | + | </syntaxhighlight> |
As you see, you need only two lines to control your bot!!! Some improvements you can do here are to replace the static 185 distance by a random distance, and to ajdust the turn angles and preferred distance. Note that the bot tries to close to the enemy when distance is greater than 200, and tries to go away when it is closer than 200, by changing the angle a little bit. | As you see, you need only two lines to control your bot!!! Some improvements you can do here are to replace the static 185 distance by a random distance, and to ajdust the turn angles and preferred distance. Note that the bot tries to close to the enemy when distance is greater than 200, and tries to go away when it is closer than 200, by changing the angle a little bit. | ||
− | + | == Trigonometric == | |
Another way to create an oscillator is to use sin/cos functions (I think it was NanoDuelist the first to use it). NanoLauLectrik also uses it. | Another way to create an oscillator is to use sin/cos functions (I think it was NanoDuelist the first to use it). NanoLauLectrik also uses it. | ||
− | < | + | <syntaxhighlight>setAhead(100 * Math.sin(getTime() / a))</syntaxhighlight> |
The parameter a will define the frecuency of the oscillation. | The parameter a will define the frecuency of the oscillation. | ||
− | You can also create more complex oscillations combining | + | You can also create more complex oscillations combining additional sin() and cos() functions. For example, you could experiment with something like this: |
− | < | + | <syntaxhighlight>setAhead(100 * (Math.sin(getTime() / a) + Math.cos(getTime() / b)));</syntaxhighlight> |
An alternative approach is the one used by NanoLauLectrik 1.0 (with similar results): | An alternative approach is the one used by NanoLauLectrik 1.0 (with similar results): | ||
− | < | + | <syntaxhighlight>setAhead(200 * Math.sin(getTime() / a) * Math.cos(getTime() / b));</syntaxhighlight> |
− | The parameters a | + | The parameters a and b will define two different frequencies that will combine to create a more complex oscillating movement. There are some interesting issues related to choosing a and b that are explained at [[Oscillator Movement/Period]]. |
− | + | == See Also == | |
+ | * [[Oscillator Movement/Period]]: Observations about the period of oscillation and [[PatternMatching]] | ||
[[Category:Movement|Oscillator Movement]] | [[Category:Movement|Oscillator Movement]] | ||
+ | {{Movement_Navbox}} |
Latest revision as of 07:12, 1 July 2010
Oscillators usually play perpendicular to enemy bot, and avoid being hit by changing direction frequently. Oscillating movement is very easy to implement, needs only a few lines of code, and can be combined with avoiding and other tricks.
Some disadvantages of oscillating movement are that you can get easily hit by an advanced targeting system, and that you have little control on your absolute position in the battlefield (you define the position relative to the enemy).
Direct
Here it goes some code similar to the one MicroAspid 1.2 was using (feel free to use it on your bots).
//** it is from onScannedRobot
if (getDistanceRemaining() == 0) { FORWARD = -FORWARD; setAhead(185 * FORWARD); }
setTurnRightRadians(e.getBearingRadians() + Math.PI/2 - 0.5236 * FORWARD * (e.getDistance() > 200 ? 1 : -1));
As you see, you need only two lines to control your bot!!! Some improvements you can do here are to replace the static 185 distance by a random distance, and to ajdust the turn angles and preferred distance. Note that the bot tries to close to the enemy when distance is greater than 200, and tries to go away when it is closer than 200, by changing the angle a little bit.
Trigonometric
Another way to create an oscillator is to use sin/cos functions (I think it was NanoDuelist the first to use it). NanoLauLectrik also uses it.
setAhead(100 * Math.sin(getTime() / a))
The parameter a will define the frecuency of the oscillation.
You can also create more complex oscillations combining additional sin() and cos() functions. For example, you could experiment with something like this:
setAhead(100 * (Math.sin(getTime() / a) + Math.cos(getTime() / b)));
An alternative approach is the one used by NanoLauLectrik 1.0 (with similar results):
setAhead(200 * Math.sin(getTime() / a) * Math.cos(getTime() / b));
The parameters a and b will define two different frequencies that will combine to create a more complex oscillating movement. There are some interesting issues related to choosing a and b that are explained at Oscillator Movement/Period.
See Also
- Oscillator Movement/Period: Observations about the period of oscillation and PatternMatching
|