|
Re: Camera to "SLOWLY" turn towards target
[Re: WINBERRY]
#293332
10/10/09 18:48
10/10/09 18:48
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
...TARGET = get the vector of your target. eg. you.x
...SPEED = set the speed of turning in 'degrees per frame'
//get TARGET's direction from ME
VECTOR pos, temp; vec_set(pos.x, TARGET.x);
vec_to_angle(temp.x, vec_sub(pos.x, my.x));
//calculate the 'difference' from MY current direction
vec_sub(temp.x, my.pan);
//limit 'difference' change-per-frame
vec_set(temp.x, vector( clamp(ang(temp.x), -SPEED, SPEED), 0, 0));
vec_scale(temp.x, time_step); vec_add(my.pan, temp.x);
...
///
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Camera to "SLOWLY" turn towards target
[Re: EvilSOB]
#293440
10/11/09 14:28
10/11/09 14:28
|
Joined: Apr 2006
Posts: 28 LB, CA, USA
WINBERRY
OP
Newbie
|
OP
Newbie
Joined: Apr 2006
Posts: 28
LB, CA, USA
|
EvilSOD, Thanks for your response. What you offered might be to far over my head, but this is what I put together:
function test() { var SPEED = 1; //TARGET = get the vector of your target. eg. you.x c_trace(holdIMAGE.x,camera.pan,ACTIVATE_SONAR); //SPEED = set the speed of turning in 'degrees per frame' //get TARGET's direction from ME
VECTOR pos, temp; vec_set(pos.x, target.x); //vec_to_angle(temp.x, vec_sub(pos.x, holdIMAGE.x)); vec_to_angle(camera.pan,vec_diff(NULL,holdIMAGE.x,camera.x)); //calculate the 'difference' from MY current direction vec_sub(temp.x, camera.x); //limit 'difference' change-per-frame vec_set(temp.x, vector( clamp(ang(temp.x), -SPEED, SPEED), 0, 0)); //vec_scale(temp.x, time_step); vec_add(camera.pan, temp.x); wait(1); } This test() will zip me to the target image, (holdIMAGE is the vector of the media_loop sprite which is an ENTITY, but not a you(? every time I tried it with you it would crash))
...but when I tried to put a 'while' statement to slow the turn down, it just kept spinning
function test_with_while() { var SPEED = 1; //TARGET = get the vector of your target. eg. you.x c_trace(holdIMAGE.x,camera.pan,ACTIVATE_SONAR); //SPEED = set the speed of turning in 'degrees per frame' //get TARGET's direction from ME
while(holdIMAGE.x != camera.x){ VECTOR pos, temp; vec_set(pos.x, target.x); //vec_to_angle(temp.x, vec_sub(pos.x, holdIMAGE.x)); vec_to_angle(camera.pan,vec_diff(NULL,holdIMAGE.x,camera.x)); //calculate the 'difference' from MY current direction vec_sub(temp.x, camera.x); //limit 'difference' change-per-frame vec_set(temp.x, vector( clamp(ang(temp.x), -SPEED, SPEED), 0, 0)); //vec_scale(temp.x, time_step); vec_add(camera.pan, temp.x); wait(1); } }
If you have any sujestions on what I'm missing here, pleae offer, otherwise, thanks again for your input.
WINBERRY
|
|
|
Re: Camera to "SLOWLY" turn towards target
[Re: WINBERRY]
#293467
10/11/09 18:04
10/11/09 18:04
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Try this one instead then, sorry this code is un-tested, I dont have much time at ATM.
function test()
{
var SPEED = 1; //set the speed of turning in 'degrees per frame'
ANGLE temp;
while(holdIMAGE!=NULL){
vec_set(temp, holdIMAGE.x);
vec_to_angle(temp, vec_sub(temp, camera.x));
vec_sub(temp, camera.pan);
temp.pan = clamp(ang(temp.pan ), -SPEED, SPEED);
vec_add(camera.pan, temp);
wait(1);
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Camera to "SLOWLY" turn towards target
[Re: WINBERRY]
#293520
10/12/09 06:13
10/12/09 06:13
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
no problem, glad to have been of help...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|