|
|
Re: [Workquestions] Pipes, Ramps and Loops
[Re: EvilSOB]
#260359
04/10/09 10:46
04/10/09 10:46
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
 ok.. any idea why the camera is not facing the ball?
//================================================================================================================================//
// //
// • Game_Main //
// //
//================================================================================================================================//
// Das Main Script regelt alle Startaktionen/Eingebundenen Scripts und Debugging Aktionen des Spiels //
//================================================================================================================================//
//================================================================================================================================//
//================================================================================================================================//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// •• Includings //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define PRAGMA_PATH "Models"
#define PRAGMA_PATH "Grafik"
#define PRAGMA_PATH "Levels"
#include "acknex.h"
#include "default.c"
#include "includes.c"
//================================================================================================================================//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// •• FONTS //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FONT* arial = "Arial#20";
//================================================================================================================================//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// •• Panels und Texte //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
PANEL* debug =
{
layer = 999;
digits(10,10,"TILT ANGLE:",arial,1,NULL);
digits(100,10,4,arial,1,player.tilt);
digits(150,10,4,arial,1,camera.tilt);
digits(100,30,4,arial,1,player.skill1);
flags = SHOW;
}
//================================================================================================================================//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// •• Funktionen //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function camera_handling()
{
VECTOR tmpV2, pos_off, ang_off; //working space
vec_set(pos_off, vector(-200,0,25)); //TWEAK :: distance of camera from ball.
vec_set(ang_off, vector(90,-15,0)); //TWEAK :: angle of camera, so it looks OVER ball
var smoothness = 0.2; //TWEAK :: smaller is smoother but slower (camera lags behind a bit)
ENTITY* cam_det = ent_create(0,0,0); //used for camera-collision-detection only.
while(1)
{
if(player)
{
//position camera
vec_set(tmpV2, pos_off);
vec_rotate(tmpV2, player.pan);
vec_add(tmpV2, player.x);
vec_sub(tmpV2, camera.x);
vec_scale(tmpV2, smoothness * time_step);
c_move(cam_det, NULL, tmpV2, IGNORE_YOU|GLIDE);
vec_set(camera.x, cam_det.x);
//rotate camera toward Player
vec_set(tmpV2, player.x); vec_sub(tmpV2, camera.x);
vec_to_angle(camera.pan, tmpV2);
if(tmpV2.x<0) { camera.pan -= 180; camera.tilt = 90-(camera.tilt-90); }
vec_add(camera.pan, ang_off);
}
proc_mode = PROC_LATE;
wait(1);
}
ent_remove(cam_det);
}
//================================================================================================================================//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// •• Aktionen //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
action plate()
{
set(my,FAT);
wait(1);
c_setminmax(my);
vec_set(my.min_x, vector(my.min_x+1, my.min_y+1, my.min_z+1));
vec_set(my.max_x, vector(my.max_x+1, my.max_y+1, my.max_z+1));
set(my,BRIGHT);
set(my,POLYGON);
}
action player_action()
{
var SetHeight = 20; //TWEAK :: distance of ball from ground.
player = my;
vec_set(my.scale_x,vector(0.5,0.5,0.5));
wait(1);
c_setminmax(my);
VECTOR tmpV;
while(1)
{
if(key_e) {c_move(my,vector( 5*time_step,0,0),nullvector,GLIDE);}
if(key_q) {c_move(my,vector(-5*time_step,0,0),nullvector,GLIDE);}
vec_set(tmpV, vector(my.x,my.y,my.z-9999));
vec_rotate(tmpV, my.pan);
c_trace(my.x, tmpV, IGNORE_ME | USE_BOX);
if(trace_hit) // if SOMETHING hit
{
vec_to_angle(tmpV, normal); //get angle of "ground". (Terrain, Entity, or WED block)
my.tilt = 90 - tmpV.y; //apply angle to ball
if((my.skill1=vec_dist(my.x,target))<SetHeight)
{ c_move(my,vector(0,0,SetHeight-my.skill1),nullvector,GLIDE); }
}
wait(1);
}
}
//================================================================================================================================//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// •• Die Main Funktion //
// //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function main()
{
fps_max = 60;
video_set(1024,768,32,2);
video_window(NULL,NULL,16,"Glayder");
level_load("test.wmb");
draw_begin();
sky_color.red = 200;
sky_color.green = 200;
sky_color.blue = 200;
wait(3);
vec_set(camera.pan, vector(90,0,0));
ent_create("ball.mdl",vector(0,0,0),player_action);
}
|
|
|
Re: [Workquestions] Pipes, Ramps and Loops
[Re: Espér]
#260376
04/10/09 12:10
04/10/09 12:10
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Just a couple of minor things, thats all. Firstly, you need to CALL camera_handling();  , after your ent_create in main would be the prime place. Second, the ang_off tweak in camera_handling is bad. My bad description I think. This tweak adjusts the camera by its pan/tilt/roll AFTER it is aimed straight at the ball. You may want to update the tweak description.A tweak of 0,0,0 puts the ball smack in the middle of the screen. I suggest ( 0, 10->25, 0 ) You gave it a pan of 90 and that forced the camera to turn 90 degrees AWAY from the ball.Third and mostly minor, the pos_off tweak in camera_handling is a bit big at x = -200. I dont know it its because the track is made of "bits" or not, but the camera can get stuck 'behind' the track. At -100 it doesnt. This could do with a bit of testing by you to try and spot the behaviour. BUT I will start working on a check in the camera_handling function to ensure this doesnt happen. Ive got a small idea already, but I would rather get your approval on the rest first. Let me know the good or bad news.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: [Workquestions] Pipes, Ramps and Loops
[Re: EvilSOB]
#260379
04/10/09 12:32
04/10/09 12:32
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Heres a new camera code which has 1> [Improved] a better description of how the ANGLE tweak works 2> [Added] Obstruction check, to prevent camera getting stuck behind walls. function camera_handling()
{
VECTOR tmpV2, pos_off, ang_off; //working space
vec_set(pos_off, vector(-200,0,25)); //TWEAK :: distance of camera from ball.
vec_set(ang_off, vector(0,20,0)); //TWEAK :: adjust angle of camera AFTER centered on player
var smoothness = 0.2; //TWEAK :: smaller is smoother but slower (camera lags behind a bit)
ENTITY* cam_det = ent_create(0,0,0); //used for camera-collision-detection only.
while(1)
{
if(player)
{
//position camera
vec_set(tmpV2, pos_off);
vec_rotate(tmpV2, player.pan);
vec_add(tmpV2, player.x);
vec_sub(tmpV2, camera.x);
vec_scale(tmpV2, smoothness * time_step);
c_move(cam_det, NULL, tmpV2, IGNORE_YOU|GLIDE);
vec_set(camera.x, cam_det.x);
//make sure camera has clear view of ball
if((c_trace(player.x,camera.x,NULL))&&(you!=cam_det))
{ vec_set(cam_det.x, target); vec_set(camera.x, target); }
//rotate camera toward Player
vec_set(tmpV2, player.x); vec_sub(tmpV2, camera.x);
vec_to_angle(camera.pan, tmpV2);
if(tmpV2.x<0) { camera.pan -= 180; camera.tilt = 90-(camera.tilt-90); }
vec_add(camera.pan, ang_off);
}
proc_mode = PROC_LATE;
wait(1);
}
ent_remove(cam_det);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: [Workquestions] Pipes, Ramps and Loops
[Re: Espér]
#260454
04/10/09 23:48
04/10/09 23:48
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Aha, now I see athe game this is inspired by, I can fully understand how it wants to move.
BUT, in trying to lock the height in place, Ive discovered a whole batch of problems with my code and its angle-detection. Some VERY serious flaws.
I'm working on it, and I'll be back once I have some news.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: [Workquestions] Pipes, Ramps and Loops
[Re: Espér]
#267492
05/24/09 12:23
05/24/09 12:23
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
True. We need fresh ideas. Mine all die from gimbal-lock.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|