|
point to target slowly
#204851
05/02/08 00:18
05/02/08 00:18
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
Ok i have a spaceship, and i want to click go there. The thing is that ordinary script will face the target instantanely, and its not real. It should acellerate and then rotate slowly , while moving, and then end on the target point.
Of course spaceship doesn't do the PAn movement, they will roll and till, the roll and till together give the movement, of course i can fake it, but well thats other thing.
Right now i can work with pan so be simpler.
So anyidea? how to do the smotth movement? i have
vec_set(temp,p1.x); // p1 = target vec_set(my_angle,p1.x); // my angle , calculate angle vec_sub(temp,my_angle); vec_to_angle(my_angle,temp); // now my angle has the pointing target angle
// AT THIS PART i can't directly set my angles to that target, it must be slowly added till it reaches the right angle, though, if spaceship is acelleratin, and rotating slowly, it will get a different toward target angle.. that must be calculated again, see where i get? //var myspeed is from 0 to 2 maximum, and has inertia already. c_move(me,vector(-myspeed,0,0),nullvector,GLIDE); // speed up
c_rotate(me,vector(my_angle.x,my_angle.tilt,my_angle.roll),USE_AXIS|GLIDE);
|
|
|
Re: point to target slowly
[Re: MMike]
#204863
05/02/08 04:23
05/02/08 04:23
|
Joined: Mar 2007
Posts: 776 Poor village - Poland ;)
tompo
User
|
User
Joined: Mar 2007
Posts: 776
Poor village - Poland ;)
|
try something like this:
var my_angle[3];
var my_target[3];
define _speed,skill1; //turning's speed
function actor_turnto(angle)
{
angle = ang(angle - MY.PAN);
if (angle > 10) {temp = my._speed;}
else{
if(angle < -10){temp = -my._speed;}
else{temp = my._speed * angle *0.1;}
}
MY.PAN += temp * time_step *2;
}
//in ship's action in while loop add
vec_diff(temp,my_target,my.pos);
result = vec_to_angle(my_angle,temp);
actor_turnto(my_angle.PAN);
c_move(me,vector(-myspeed,0,0),nullvector,GLIDE); // speed up why your ship going in wrong direction, not forward?
Last edited by tompo; 05/02/08 04:27.
Never say never.
|
|
|
Re: point to target slowly
[Re: tompo]
#204909
05/02/08 12:05
05/02/08 12:05
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
Im not sure yet, why i did that, but, it seeams that when i get the angle to the target, my ship flip and then it would move backwards, lol. So i guess i modeled my model wrong, and i just did that small correction for testing.
About your code, changing the pan , will rotate it correctly? i mean, the x pos will pointing for the new pan or relative? thats why i use c_rotate.
|
|
|
Re: point to target slowly
[Re: MMike]
#204932
05/02/08 14:16
05/02/08 14:16
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
while(1){ vec_diff(temp,p1.x,my.x); // get target(p1) and my angle result = vec_to_angle(my_angle,temp); rotate_speed = 0.5; // this will simulate a bit of inertia
if(my.pan<my_angle.pan){c_rotate(me,vector(rotate_speed,0,0),USE_AXIS|GLIDE);} if(my.pan>my_angle.pan){c_rotate(me,vector(-rotate_speed,0,0),USE_AXIS|GLIDE);} if(my.tilt<my_angle.tilt){c_rotate(me,vector(0,rotate_speed,0),USE_AXIS|GLIDE);} if(my.tilt>my_angle.tilt){c_rotate(me,vector(0,-rotate_speed,0),USE_AXIS|GLIDE);} if(my.roll<my_angle.roll){c_rotate(me,vector(0,0,rotate_speed),USE_AXIS|GLIDE);} if(my.roll>my_angle.roll){c_rotate(me,vector(0,0,-rotate_speed),USE_AXIS|GLIDE);}
it works well, but.. sometimes it will go in a weird way, if angle becomes negative or positive.. i know that if angle is > 360 i can consider it 0 º but if <360 it can be 0 º too this will confuse the math here, i guess..
So i don't know if i should use relative or absolute rotation.. and if have to say pan%=360 or not :S
Last edited by MMike; 05/02/08 15:38.
|
|
|
Re: point to target slowly
[Re: MMike]
#205334
05/05/08 21:42
05/05/08 21:42
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
Tompo can you explain your script. :S it does not use c_rotate, and i need collision .
Last edited by MMike; 05/05/08 21:43.
|
|
|
Re: point to target slowly
[Re: MMike]
#205490
05/06/08 20:04
05/06/08 20:04
|
Joined: Oct 2007
Posts: 116
sydan
Member
|
Member
Joined: Oct 2007
Posts: 116
|
I have this proble mas well its a huge draw back and Im sorry to say that I haven't managed to find a solution yet either. My method works byt checking to see if the target angle is bigger or smaller that the current angle and then turning according;y but this doesn't work over the 0 - 360 boundary! So I'm stuck too. Are there any crazy experts who have a fool proof answer to what seems like a global question?
For some reason, my ambition always seems to beat my ability.
|
|
|
Re: [DONE-SUB]point to target slowly
[Re: MMike]
#205593
05/07/08 14:26
05/07/08 14:26
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
Ok i finally got this to work after somedays of testing and working hard. To get a point to target that is really optimized to turn the shortest angle between my angle and target angle, i had to break the angles in quadrants, and study all possibilites and write a formula for them. //quadrant here means...Quartenion!! var my_q; //my angle quadrant or quartenion
var target_q; //target quadrant
var comp; // complementar angle to best short angle calculations
var d_sign; //rotate direction
var d_count; // how much we need to rotate to get to the target
function turn_target {
var ang_temp[3];
vec_diff(ang_temp,p1.x,my.x);
vec_to_angle(my_angle.pan,ang_temp); turn my_angle vector
if(my_angle.pan<0){my_angle.pan+=360;} //convert angle to 360 range if needed
/// HERE i assign the target quadrant
if(my_angle.pan<=360 && my_angle.pan>270){target_q=4;}
if(my_angle.pan<=270 && my_angle.pan>180){target_q=3;}
if(my_angle.pan<=180 && my_angle.pan>90){target_q=2;}
if(my_angle.pan<=90 && my_angle.pan>=0){target_q=1;}
//Here i'll assign in which my angle quadrant is
if(my.pan<=360 && my.pan>270){my_q=4;}
if(my.pan<=270 && my.pan>180){my_q=3;}
if(my.pan<=180 && my.pan>90){my_q=2;}
if(my.pan<=90 && my.pan>=0){my_q=1;}
// Here i set the complement angle constrain to 360 range
comp%=360;
comp=my_angle.pan+180; // complement angle = my angle + 180
// if my angle is within the target (+/-2) no need to calculate , otherwise calculate:
if(!(my.pan<(my_angle+2) && my.pan>(my_angle-2)) ){
//if the target quadrant is different from the my angle quadrant
if(target_q!=my_q){
// Now calculate all the quadrant interactions and possibilites.
//adjacents quadrant - simple - done
if(target_q==1 && my_q==2){d_sign=-1;d_count=my.pan-my_angle.pan;}else{if(my_q==1 && target_q==2){d_sign=1;d_count=my_angle.pan-my.pan;}}
if(target_q==2 && my_q==3){d_sign=-1;d_count=my.pan-my_angle.pan;}else{if(my_q==2 && target_q==3){d_sign=1;d_count=my_angle.pan-my.pan;}}
if(target_q==3 && my_q==4){d_sign=-1;d_count=my.pan-my_angle.pan;}else{if(my_q==3 && target_q==4){d_sign=1;d_count=my_angle.pan-my.pan;}}
if(target_q==4 && my_q==1){d_sign=-1;d_count=360-(my_angle.pan-my.pan);}else{if(my_q==4 && target_q==1){d_sign=1;d_count=360-(my.pan-my_angle.pan);}}
if(target_q==2 && my_q==4){
if(my.pan<comp){d_sign=-1;d_count=my.pan-my_angle.pan; } //manual complement -done
if(my.pan>comp){d_sign=1;d_count=360-(my.pan-my_angle.pan); } //manual complement - done
}else
{if(my_q==2 && target_q==4){
if(my.pan<comp){d_sign=-1; d_count=360-(my_angle.pan-my.pan); } //manual complement - done
if(my.pan>comp){d_sign=1; d_count=my_angle.pan-my.pan; } //manual complement - done
}}
if(target_q==3 && my_q==1){
if(my.pan<comp){d_sign=-1; d_count=360-(my_angle.pan-my.pan); } //manual complement - done
if(my.pan>comp){d_sign=1; d_count=my_angle.pan-my.pan; } //manual complement - done
}else
{if(my_q==3 && target_q==1){
if(my.pan<comp){d_sign=-1; d_count=my.pan-my_angle.pan; } //manual complement - done
if(my.pan>comp){d_sign=1; d_count=360-(my.pan-my_angle.pan); } //manual complement -done
}}
}else{if(my.pan>my_angle.pan){d_count=my.pan-my_angle.pan; d_sign=-1;}else{d_sign=1; d_count=my_angle.pan-my.pan;}}
}
// D_Count stores how much we still need to rotate, for the shortest angle
if(d_count>0){
// Now rotate the my pan, to that angle...
if(d_sign==1){c_rotate(me,vector(rotate_speed,0,0),USE_AXIS|GLIDE);}
if(d_sign==-1){c_rotate(me,vector(-rotate_speed,0,0),USE_AXIS|GLIDE);}
d_count-=rotate_speed;
if(my.pan<0){my.pan+=360;} //convert angle to 360 range here, due to c_rotate mutation ( c_rotate tranform my pan in a -180: 180 range and not 0..360
}else{d_count=0;}
}
Thats all... Hope i helped.. this toooke alot of work.. believe
Last edited by MMike; 05/07/08 19:40.
|
|
|
Re: [DONE-SUB]point to target slowly
[Re: MMike]
#205621
05/07/08 16:44
05/07/08 16:44
|
Joined: Oct 2007
Posts: 116
sydan
Member
|
Member
Joined: Oct 2007
Posts: 116
|
Woaw okay I see if it works with me. Thanks for the code! I bet it to alot by the looks of the calcualtions!!!
For some reason, my ambition always seems to beat my ability.
|
|
|
|