What object is this cross in a circle? - Printable Version +- Colobot Forum - International Colobot Community (https://colobot.info/forum) +-- Forum: [Archive] New forum (2015-2019) (https://colobot.info/forum/forumdisplay.php?fid=76) +--- Forum: Colobot: Gold Edition Basics (https://colobot.info/forum/forumdisplay.php?fid=58) +---- Forum: General (https://colobot.info/forum/forumdisplay.php?fid=59) +---- Thread: What object is this cross in a circle? (/showthread.php?tid=743) |
What object is this cross in a circle? - Rinoldo - 03-18-2016 Now I'm in the 4 task of Tropica (3-th mission). I'm going to try pass it using only programming. But I couldn't find in Categories part of the Help anything about this object, cross in a circle. How can I reffer to it, and get it's direction, position.z? [img][/img] RE: What object is this cross in a circle? - krzys_h - 03-18-2016 The category of this object is Target2, it should probably be added to the documentation somewhere RE: What object is this cross in a circle? - Rinoldo - 03-18-2016 Thank you! I tried to get to that cross by this code: Code: object tar2 = radar(Target2); Code: goto(tar2.position - 2); RE: What object is this cross in a circle? - tomaszkax86 - 03-18-2016 tar2.position is of type point, which has 3 floats. You need to save it to a variable and calculate position: Code: point pos = tar2.position; You might want to use object's orientation (angle) to calculate position using cos() and sin(). Side note: goto() is kinda like cheating. It's too easy. Try doing the same using motor() and jet(). I think this could be a good idea for a programming challenge. A speed run or something. RE: What object is this cross in a circle? - krzys_h - 03-18-2016 goto() can move only to locations on the ground (it ignores the height in point given as parameter), so you have to write your own movement algorithm using functions like jet(), turn() and move() [or motor() if you are a bit more expirenced and want to move and turn at the same time] RE: What object is this cross in a circle? - Rinoldo - 03-18-2016 (03-18-2016, 12:50 PM)tomaszkax86 Wrote: tar2.position is of type point, which has 3 floats. You need to save it to a variable and calculate position: I'v got some positive results, thanks! The idea to calculte position of an object is quite interesting. Could you explain with some example, please, how to get angle of an object using cos and sin? For example, Target2? (03-18-2016, 12:50 PM)tomaszkax86 Wrote: Side note: goto() is kinda like cheating. It's too easy. Try doing the same using motor() and jet(). I think this could be a good idea for a programming challenge. A speed run or something. Yes, I'm inclined to agree with you. But I confronted with some troubles using move(). In previous mission my WheeledShooter every time, when was stopped by a building or ruin or a bot, continued to do move() without end. Though there was errmode() in the code. In the same time, errmode() worked correctly when WheeledShooter confronted with some plant. Why in one case the game didn't take stopping as an error and in other case took it as an error and performed errmode() that is a big riddle for me. Here is that code: Code: object ant, power; RE: What object is this cross in a circle? - tomaszkax86 - 03-18-2016 After you detected object using radar(), you can access its orientation easily: Code: object item = radar(Target2); Angle in degrees can be used in sin() and cos() to compute Cartesian direction. In standard math: Code: float radius = 5.0f; dx and dy will be the change you need to apply to position. radius is the distance from the object. You can add dx and dy directly to base position and obtain where you need to move: Code: point pos = tar2.position; I'm not sure if it will work like this in CBot because coordinates or orientation might be different, so you might have to test this and adapt if necessary. RE: What object is this cross in a circle? - Rinoldo - 03-19-2016 (03-18-2016, 07:04 PM)tomaszkax86 Wrote: Angle in degrees can be used in sin() and cos() to compute Cartesian direction. In standard math: It's not clear for me how do we know that we need to put into radius exactly 5.0f? Isn't the distance from the object changes as the bot moves? And what does means the letter f after 5.0? RE: What object is this cross in a circle? - melex750 - 03-19-2016 The "f" is used to express a literal float value in C++, it doesn't exist in CBOT. Code: // orientation is the direction the object is facing. 0-360 RE: What object is this cross in a circle? - Rinoldo - 03-19-2016 malex750, thanks a lot for the code! Would you be so kind to explain, why is 0 and 360 == east, 90 == north and 180 == west? As we know, in a compass 0 is north, 180 is south, 90 is east and 270 is west. How do I have to understand cardinals in the game? RE: What object is this cross in a circle? - Simbax - 03-19-2016 https://en.wikipedia.org/wiki/Polar_coordinate_system RE: What object is this cross in a circle? - Rinoldo - 03-26-2016 Hi everyone! I added "ori += 90" into the code above and tried: Code: float dist = -5.0; // <------change this to 5.0 to go in front of the object RE: What object is this cross in a circle? - krzys_h - 03-26-2016 (03-26-2016, 06:05 PM)Rinoldo Wrote: First of all not all crosses oriented in the same manner. So if you apply that code, the FlyingShooter will go sometimes to the front of a circle, sometimes to the rear side of the next circle.This is an interesting note. It's probably related to how the objects are placed in the level file. A most simple fix would be to calculate positions on both front and back of the circle and chose the one that is closer to the robot. If you want to see a program I wrote a long time ago to pass this mission, it's still on our old and outdated program database. If I remember correctly it's not perfect and sometimes had problems with one of the checkpoints. The comments in the program are written in Polish unfortunately. http://colobot.info/programdb/?page=view-plain&id=6 |