|
1 registered members (Quad),
3,455
guests, and 4
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: [REQ[ How to smoothly turn a camera to a target?
[Re: exile]
#393998
02/08/12 23:08
02/08/12 23:08
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
It definitely would help.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: [REQ[ How to smoothly turn a camera to a target?
[Re: Superku]
#394001
02/08/12 23:16
02/08/12 23:16
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Yeah, post code.
Its not clear if you want the camera to MOVE toward the enemy, or to just LOOK AT the target...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: [REQ[ How to smoothly turn a camera to a target?
[Re: EvilSOB]
#394105
02/10/12 04:04
02/10/12 04:04
|
Joined: Apr 2005
Posts: 796 U.S.A. Michigan
exile
OP
User
|
OP
User
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
|
function normalCamera()
{
if(target_enemy == NULL)
{
camera.pan -= mouse_force.x * 12 * time_step;
camera.tilt += mouse_force.y * 8 * time_step;
camera.tilt = clamp(camera.tilt, -30, 10);
temp = fcos(camera.tilt, -camera_distance);
vec_set(camera.x, vector(my.x + fcos(camera.pan, temp),my.y + fsin(camera.pan, temp),my.z + 20 + fsin(camera.tilt, -camera_distance)));
vec_diff(tempV.x, camera.x, my.x); //find the vector from the player to the camera
vec_normalize(tempV.x, 16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(tempV.x, camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
result = c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
if(result > 0)
{
vec_diff(tempV.x, my.x, target.x); //find the vector from the point the trace hit to the player
vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(camera.x, target.x); //place the camera at the trace hit point
vec_add(camera.x, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
}
}
function battle_cam() // 2.5D Camera
{
var batCamZoom;
if(target_enemy != NULL)
{
vec_lerp(camCenter,my.x,target_enemy.x,0.5);
temp = fcos(camera.tilt, -autoCamera_distance);
vec_set(tempV3, target_enemy.x);
vec_sub(tempV3, my.x);
vec_to_angle(cameraAng, tempV3);
camera.pan = cameraAng.pan+90;
camera.tilt = -10;
batCamZoom = vec_dist(my.x,target_enemy.x);
autoCamera_distance = batCamZoom + 300;
vec_set(camera.x, vector(camCenter.x + fcos(camera.pan, temp),camCenter.y + fsin(camera.pan, temp),camCenter.z + fsin(camera.tilt, -autoCamera_distance)));
result = c_trace(camCenter.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
DEBUG_VAR(camera.pan,10);
if(result > 0)
{
vec_diff(tempV.x, camCenter.x, target.x); //find the vector from the point the trace hit to the player
vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(camera.x, target.x); //place the camera at the trace hit point
vec_add(camera.x, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
}
}
Essentially, I would like the camera to smoothly switch between the two camera systems. Tried using vec_lerp, bot alas I am the retarded hahaha
Last edited by exile; 02/11/12 01:57.
|
|
|
Re: [REQ[ How to smoothly turn a camera to a target?
[Re: exile]
#394231
02/11/12 04:35
02/11/12 04:35
|
Joined: Apr 2005
Posts: 796 U.S.A. Michigan
exile
OP
User
|
OP
User
Joined: Apr 2005
Posts: 796
U.S.A. Michigan
|
Sorry for the double post, but I have another problem. I am trying to have my targeting system set up where... Player is scanning for entity Entity gets scanned Target indicator is created at entities position Entity becomes outside of the scan range Target indicator goes away. For the life of me I cant think of a way to do this properly. Im not even sure if this would be the best way. function scanForEnemies() //This gets called in the player loop. { c_scan(my.x,my.pan,vector(60,0,200),SCAN_ENTS | SCAN_LIMIT); }
function beingTargeted() //This is the scan event { dvar = result; if(targetEnt == NULL) //Prevents more than one targeting indicator being created { targetEnt = ent_create("target.tga",my.x,targetIcon); //Creates the Target Icon } }
|
|
|
Re: [REQ[ How to smoothly turn a camera to a target?
[Re: exile]
#394233
02/11/12 04:51
02/11/12 04:51
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
1st problem: Can't you set two vectors and two angles to the appropriate positions and angles?
normalCamera() calculates the vector camera_position1 (instead of camera.x) and the angle (vector) camera_angle1, the other function *_2. Now you can easily lerp between the positions:
lerp_factor... vec_lerp(camera.x,camera_position1,camera_position2,lerp_factor);
You may have to use ang() when you calculate camera pan from the angles.
2nd problem: I would create the target icon only once, then set it invisible when you don't need it.
ENTITY* targetMarker; ENTITY* targetEnt; ... targetMarker = ent_create("target.tga",...); ... function scanForEnemies() //This gets called in the player loop. { targetEnt = NULL; c_scan(my.x,my.pan,vector(60,0,200),SCAN_ENTS | SCAN_LIMIT); if(you) { targetEnt = you; reset(targetMarker,INVISIBLE); vec_set(targetMarker.x,your.x); } }
Alternatively, you can set the pointer targetEnt in an event function like you currently do, e.g. as follows:
var min_dist;
function scanForEnemies() //This gets called in the player loop. { min_dist = 9999; targetEnt = NULL; c_scan(my.x,my.pan,vector(60,0,200),SCAN_ENTS | SCAN_LIMIT); if(targetEnt) { reset(targetMarker,INVISIBLE); vec_set(targetMarker.x,targetEnt.x); } }
function beingTargeted() //This is the scan event { if(result < min_dist) { min_dist = result; targetEnt = me; } }
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: [REQ[ How to smoothly turn a camera to a target?
[Re: exile]
#394236
02/11/12 07:03
02/11/12 07:03
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Try this out...
function normalCamera_2()
{
VECTOR target_pos; ANGLE target_ang;
var move_lerp=0.25; var ang_lerp=0.25;
if(target_enemy == NULL)
{
target_ang.pan = camera.pan - mouse_force.x * (12/ang_lerp) * time_step;
target_ang.tilt = camera.tilt + mouse_force.y * (8/ang_lerp) * time_step;
target_ang.tilt = clamp(target_ang.tilt , -30, 10);
temp = fcos(target_ang.tilt , -camera_distance);
target_ang.roll=0;
target_pos.x = my.x + fcos(camera.pan, temp);
target_pos.y = my.y + fsin(camera.pan, temp);
target_pos.z = my.z + 20 + fsin(camera.tilt, -camera_distance);
vec_diff(tempV.x, target_pos, my.x); //find the vector from the player to the camera
vec_normalize(tempV.x, 16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(tempV.x, target_pos); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
result = c_trace(my.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
if(result > 0)
{
vec_diff(tempV.x, my.x, target.x); //find the vector from the point the trace hit to the player
vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(target_pos, target.x); //place the camera at the trace hit point
vec_add(target_pos, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
vec_lerp(camera.x, camera.x, target_pos, move_lerp);
vec_lerp(camera.pan, camera.pan, target_ang, ang_lerp );
}
}
function battle_cam_2() // 2.5D Camera
{
VECTOR target_pos; ANGLE target_ang;
var move_lerp=0.25; var ang_lerp=0.25;
var batCamZoom;
if(target_enemy != NULL)
{
vec_lerp(camCenter,my.x,target_enemy.x,0.5);
temp = fcos(camera.tilt, -autoCamera_distance);
vec_set(tempV3, target_enemy.x);
vec_sub(tempV3, my.x);
vec_to_angle(cameraAng, tempV3);
target_ang.pan = cameraAng.pan+90;
target_ang.tilt = -10;
target_ang.roll = 0;
batCamZoom = vec_dist(my.x, target_enemy.x);
autoCamera_distance = batCamZoom + 300;
target_pos.x = camCenter.x + fcos(camera.pan, temp);
target_pos.y = camCenter.y + fsin(camera.pan, temp);
target_pos.z = camCenter.z + fsin(camera.tilt, -autoCamera_distance);
result = c_trace(camCenter.x, tempV.x, IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS); //trace from the player to 16 quants behind the camera.
DEBUG_VAR(camera.pan,10);
if(result > 0)
{
vec_diff(tempV.x, camCenter.x, target.x); //find the vector from the point the trace hit to the player
vec_normalize(tempV.x, 16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(target_pos, target.x); //place the camera at the trace hit point
vec_add(target_pos, tempV.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
vec_lerp(camera.x, camera.x, target_pos, move_lerp);
vec_lerp(camera.pan, camera.pan, target_ang, ang_lerp );
}
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|