﻿ My super move is not so super after all.

 My super move is not so super after all. Quartofel I have potato blood in my veins. Posts: 34 Threads: 13 Joined: Dec 2016 Reputation: 7 #1 03-27-2017, 06:38 PM (This post was last modified: 03-27-2017, 06:38 PM by Quartofel.) Code:```extern void object::Main() {     move(5);     smove(5); } void object::smove(int dist) {     point b = chkpos(dist), pos = this.position;     //while(distance2d(b, this.position)>1) //Y U NO WORK        while(true)     {         point c = chkpos(20);         if(topo(c)>this.position.z){motor(0.1,0.1); adjalt(7,8);}         else{motor(1,1);adjalt(4,5);}     } } void object::adjalt(int min, int max) {     int alt = this.altitude;     if(altmax){while(alt>max){jet(-0.65);alt = this.altitude;}}     if(alt<1 && altmin){motor(0.2, 0.2); jet(1);alt = this.altitude;}}     jet(0); } point object::chkpos(int c) //winny bledow przy przelotach w okolicy wysokich struktur {     int a, b, ori = this.orientation;     point t = this.position, p;     if(0 <= ori && ori <= 90){ori = 90 - ori; a = c*cos(ori); b = c*sin(ori); p.x=(t.x+a); p.y=(t.y+b);} //I     if(90 <= ori && ori <= 180){ori = 180 - ori;a = c*cos(ori); b = c*sin(ori); p.x=(t.x-a); p.y=(t.y+b);} // II     if(180 <= ori && ori <= 270){ori = 270 - ori;a = c*cos(ori); b = c*sin(ori); p.x=(t.x-a); p.y=(t.y-b);} //III     if(270 <= ori && ori <= 360){ori = 360 - ori;a = c*cos(ori); b = c*sin(ori); p.x=(t.x+a); p.y=(t.y-b);} //IV     p.z = topo(p);     return p; }```I've tried everything I could. It should slow down and ascend higher if encountered terrain higher than it's altitude. Written for wasp. Help, I don't know what's wrong ;-; It won't go for set distance, and sometimes it climbs obstacles properly, sometimes don't. Don't know why. Si vis pace, para bellum. krzys_h The Programmer Posts: 828 Threads: 26 Joined: Oct 2012 Reputation: 113 #2 03-27-2017, 07:31 PM What is the chkpos function supposed to actually do? Return a point c meters in front of the robot? (I'm too lazy to try to understand the whole code ) If so... why not just Code:```point object::chkpos(int c) {    point p;    p.x = this.position.x + cos(this.orientation) * c;    p.y = this.position.y + sin(this.orientation) * c;    p.z = topo(p);    return p; }``` I can't see any other immediate problems, other than the way you do the altitude choice could probably be done better - I'd just let the wasp stay at around z=max(topo(this.position), chkpos(20))+some_arbitrary_altitude_above_ground. Anyway, your code seems to work fine for me, unless you have some level with terrain changes big enough for it to break. Mrocza Master Posts: 152 Threads: 7 Joined: Oct 2012 Reputation: 25 #3 03-28-2017, 07:57 AM (This post was last modified: 03-28-2017, 07:57 AM by Mrocza.) It seems needlessly complicated to me for some reason. You can use the wasp's velocity with the chkpos() to return a point x seconds in front of it. Then adjust the motor to the ratio of these two points' topo(). For jet() I always do a single line: Code:`jet(( targetPosZ - this.position.z ) / smoothingFactor)` My Code Battle League program: MhrodeBattle.txt Welcome back, Mrocza. You last visited: Sunday, July 7th, 2013, 02:12 pm  http://imgur.com/L3Y8bQz krzys_h The Programmer Posts: 828 Threads: 26 Joined: Oct 2012 Reputation: 113 #4 03-28-2017, 03:12 PM (03-28-2017, 07:57 AM)Mrocza Wrote: You can use the wasp's velocity with the chkpos() to return a point x seconds in front of it.Oh, I totally forgot object.velocity is now a thing... and I'm the one who implemented it This solution would be even better probably « Next Oldest | Next Newest »