2 registered members (AndrewAMD, juanex),
1,247
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Camera glide along walls?
[Re: Superku]
#424438
06/16/13 01:16
06/16/13 01:16
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
In order to trace, I would assume c_trace is the only function to use, unless I am mistaken. In order to use c_trace, don't you need two vertices to create the c_trace beam? Okay, I can find a vertex on my player character by opening up MED. But what about the camera that is following my character? How can I find a vertex on the camera following my character in order to complete the c_trace beam? Here is my code for the camera following my character:
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-200,-35,45)); //camera position relative to the player
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_add(camera.x,ent.x); // add player position
vec_set(camera.pan,vector(ent.pan,-5,0)); // look in player direction, slighty down
wait(1);
}
}
How would I find the vertex for the camera from this code, or do I really need the vertex of the camera to do the c_trace?
Last edited by Ruben; 06/16/13 01:21.
|
|
|
Re: Camera glide along walls?
[Re: Ruben]
#424439
06/16/13 01:40
06/16/13 01:40
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Normally you don't use vertices when dealing with c_trace (or any other function), I assume in your case you simply grab the position (!!) of two vertices and use this, not the vertices themselves. The function prototype for c_trace reads as follows: c_trace(VECTOR* from, VECTOR* to, var mode) You only need to have or calculate two positions. This could be done as follows - the code is untested, but it should give you the right idea:
function camera_follow(ENTITY* ent)
{
var camera_distance, camera_distance_max;
VECTOR camera_target;
camera_distance_max = vec_length(vector(-200,-35,45));
camera_distance = camera_distance_max;
while(1)
{
// calculate camera target
vec_set(camera_target.x,vector(-200,-35,45)); //camera position relative to the player
vec_rotate(camera_target.x,ent.pan); // rotate the camera position with the player
vec_add(camera_target.x,ent.x); // add player position
camera_distance += (camera_distance_max-camera_distance)*0.2*time_step; // for a smoother wall alignment
// check for walls
set(ent,PASSABLE);
result = c_trace(ent.x,camera_target,IGNORE_PASSABLE);
reset(ent,PASSABLE);
if(trace_hit) camera_distance = minv(camera_distance,result);
// set camera position
vec_lerp(camera.x,ent.x,camera_target.x,camera_distance/camera_distance_max);
vec_set(camera.pan,vector(ent.pan,-5,0)); // look in player direction, slighty down
wait(1);
}
}
EDIT: If the camera still looks through walls, try to replace if(trace_hit) camera_distance = minv(camera_distance,result); with if(trace_hit) camera_distance = minv(camera_distance,result-32); or any other negative value.
Last edited by Superku; 06/16/13 01:43.
"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: Camera glide along walls?
[Re: Superku]
#424440
06/16/13 02:49
06/16/13 02:49
|
Malice
Unregistered
|
Malice
Unregistered
|
Wow Superku that is real great. Good to see how to use all those vector instructions I've never learned. I had to look up vec_lerp() lol. Is there a speed advantage to the set/reset PASSABLE over IGNORE_ME ? I don't understand why you did it. I don't mean to hijack I'm just assuming that if I got confused then the OP might have as well. (Ok I really wanted to know ) By-the-way THANK YOU Superku for my new camera obstacle base code.
Last edited by Malice; 06/16/13 02:57.
|
|
|
Re: Camera glide along walls?
[Re: Superku]
#424491
06/17/13 08:10
06/17/13 08:10
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
EDIT: If the camera still looks through walls, try to replace if(trace_hit) camera_distance = minv(camera_distance,result); with if(trace_hit) camera_distance = minv(camera_distance,result-32); or any other negative value. I would suggest using an entity as camera collider instead of shorten the ray by a constant.
ENTITY *entCameraCollider;
function camera_collider_startup ()
{
entCameraCollider = ent_create(CUBE_MDL,vector(0,0,-100000),NULL);
vec_fill(entCameraCollider.max_x, 16);
vec_fill(entCameraCollider.min_x, -16);
set ( entCameraCollider, INVISIBLE );
}
function camera_follow(ENTITY* ent)
{
...
// check for walls
set(ent,PASSABLE);
ENTITY *entMeOld = me;
me = entCameraCollider;
result = c_trace( ent.x, camera_target, IGNORE_PASSABLE | USE_BOX );
reset(ent,PASSABLE);
me = entMeOld;
if(trace_hit) camera_distance = minv(camera_distance,result);
...
}
Last edited by txesmi; 06/17/13 08:28.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|