[newton] problems with camera!

Posted By: HackerL

[newton] problems with camera! - 11/13/06 19:40

Ok so i was programming RESET script for my level. It works fine, even with error.
But i need to take off the error!

Here is the problems



And here is my cam script where error is!

Code:
 starter move_camera()
{
camera.arc=72;
camera.clip_near=20;
camera.clip_far=24000;

var cam_ang[3];
var cam_dist=500;
cam_ang.pan=180;
cam_ang.tilt=18;
cam_ang.roll=0;

while(!p_vehicle){wait(1);}

while(1)

{
if(key_b)
{
cam_ang.pan = p_vehicle.pan - 0;
}
else
{
cam_ang.pan = p_vehicle.pan - 180;
}


{
if(mouse_right)
{
//cam_angA.pan+=10*mouse_force.x;
cam_ang.tilt=clamp(cam_ang.tilt+(10*mouse_force.y),5,80);
}

cam_dist=clamp(cam_dist-mickey.z,200,2000);

camera.x=p_vehicle.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.y=p_vehicle.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.z=p_vehicle.z+sin(cam_ang.tilt)*cam_dist;

vec_set(temp,p_vehicle.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);


wait(1);
}
}





Here is my level RESET script.

Code:
function reset_level()
{
loadingscreen.pos_x = (screen_size.x - bmap_width(loading_lv))/2; //centers loading screen
loadingscreen.pos_y = (screen_size.y - bmap_height(loading_lv))/2;

loadingscreen.visible = on; //displays loading screen
wait(3);
sleep(2);
loadingscreen.visible = off; //clears screen
bmap_purge(loading_lv);
LOAD_LEVEL (s_level); //level name
dll_handle=newtonHandle;
NewtonAddMap(s_level,0);

}
on_t = reset_level(); //the game is going to be restarted




The level is reseting, but when it has reseted, then my game shows errors, what you can see in pictures. The game still is driveable, but on more thing once i have reseted level then second time that error isnt showing up!
Posted By: testDummy

Re: [newton] problems with camera! - 11/14/06 06:39

This question doesn't really seem to be related to Newton directly.
Perhaps, questions of this nature should be posted in the 'scripting' forum category instead.
red: removed element
blue: pay attention to
Entity pointers might be reset to null on level_load, but while(1) functions may 'persist' or continue.
Code:

starter move_camera() {
//proc_kill(4); //only one instance of this function should be running
camera.arc=72;
camera.clip_near=20;
camera.clip_far=24000;

var cam_ang[3];
var cam_dist=500;
cam_ang.pan=180;
cam_ang.tilt=18;
cam_ang.roll=0;

//while(!p_vehicle){wait(1);} // removed; probably unnecessary

while(1) {
if (p_vehicle != null) {
if(key_b) {
cam_ang.pan = p_vehicle.pan - 0;
} else {
cam_ang.pan = p_vehicle.pan - 180;
}
//{ //dangling bracket removed

if(mouse_right) {
//cam_angA.pan+=10*mouse_force.x;
cam_ang.tilt=clamp(cam_ang.tilt+(10*mouse_force.y),5,80);
}

cam_dist=clamp(cam_dist-mickey.z,200,2000);

camera.x=p_vehicle.x+cos(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.y=p_vehicle.y+sin(cam_ang.pan)*(cam_dist*cos(cam_ang.tilt));
camera.z=p_vehicle.z+sin(cam_ang.tilt)*cam_dist;

vec_set(temp,p_vehicle.x);
vec_sub(temp,camera.x);
vec_to_angle(camera.pan,temp);
}
wait(1);
}
}

function reset_level() {

//dll_handle = newtonHandle;
//NewtonRemoveMap(); //or maybe instead
//NewtonRemoveAllBodies();

loadingscreen.pos_x = (screen_size.x - bmap_width(loading_lv))/2; //centers loading screen
loadingscreen.pos_y = (screen_size.y - bmap_height(loading_lv))/2;
loadingscreen.visible = on; //displays loading screen
wait(3);
sleep(2); //TD: why are we sleeping?
loadingscreen.visible = off; //clears screen
bmap_purge(loading_lv);
LOAD_LEVEL (s_level); //level name
dll_handle=newtonHandle;
NewtonAddMap(s_level,0);
}
//on_t = reset_level(); //the game is going to be restarted
on_t = reset_level; //TD: only use parenthesis when actually calling function


edited: Moved wait(1) into while(1) block.
Posted By: HackerL

Re: [newton] problems with camera! - 11/14/06 17:12

Thanks again testdummy for responding, ytour script wroks liek mine!

And when i restart game, then it says Possible endless loop in move_camera
Posted By: testDummy

Re: [newton] problems with camera! - 11/14/06 20:50

Oops, wait(1) instruction should be in while(1) block.
The code in my previous post was edited.
Posted By: HackerL

Re: [newton] problems with camera! - 11/15/06 18:04

Oh men, you have helped me so much past few questions How can i ever repay you!
© 2024 lite-C Forums