Colobot Forum - International Colobot Community

Full Version: MinePlanter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have an idea to make a robot what will plant mines. I decided to use Sniffer and "produce" command, because of (un)limitations of colobot

For now it's so simple

Quote:extern void object::MinePlanter()
{
sniff();
produce(Mine);
}


I wonder how to make Sniffer produce the Mine in front of him - do you guys have any idea?
You need to use robot's position and orientation to calculate position in front of it and use it as an argument for produce. This code should do it:

Code:
float angle = orientation;
float radius = 5.0;

point pos;
pos.x = position.x + radius * cos(angle);
pos.y = position.y + radius * sin(angle);

produce(pos, orientation, Mine);

If you want it to make a mine behind it, just add 180 to "angle". You can change the distance by changing variable "radius".
Thank you! That's exactly what i need

Quote:extern void object::MinePlanter()
{
float angle = orientation;
float radius = 1.7;

point pos;
pos.x = position.x + radius * cos(angle);
pos.y = position.y + radius * sin(angle);


sniff();
produce(pos, orientation, Mine);
}

@edit.
That's pretty strange. I used "produce" command before "sniff" and when I runned this program while robot was standing in place, it was OK. When program finished I could even go thru the mine. The problem was when I runned program while robot was moving - then Mine was destroying robots immediately.
So i had to use "sniff" before "produce" - then robot needs to stop to sniff and it works fine