4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Camera passing through wall
[Re: DriftWood]
#471155
02/21/18 03:01
02/21/18 03:01
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Kartoffel answers perfectly.
Haha - did the "hit" part escape you? Go to c_trace in the manual. There you'll find the link to the "hit" struc that holds even more cool data after a trace. The concept of nx is the a Normal. A Normal unit vector is common in all 3D. It would truly be amazing if you have been working with 3D for so long and have no idea what a Normal are.
Here is your reading https://en.m.wikipedia.org/wiki/Normal_(geometry) Thanks for the sprinkling of condescension in your tone. I saw that one coming. I knew you couldn't reasonably be that chipper. ;-) However, as long as I have been doing this, this is a part-time gig for me, as I have my full time bread and butter job. Got to keep a roof over my head. :-) You are right, though. I should have linked it to the hit variable, and looked that one up. Learned a lesson. Thank you for the advice on what a Normal is.
Last edited by Ruben; 02/21/18 03:24.
|
|
|
Re: Camera passing through wall
[Re: DriftWood]
#471157
02/21/18 03:10
02/21/18 03:10
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Wait!!! Cool idea! Why not just push off the wall using it's own normal?! Yeah that could work!
Vec_set( vecTarget, hit.x);
Vec_set ( vec_temp, hit.nx);
Vec_normalize ( vec_temp, 20);
Vec_add ( vecTarget, vec_temp);
// Bam!!! Virtual Monkey!!!
I tried both your ideas inside the HIT_TARGET brackets, and both of them are not working. I am still seeing the vertical blue line on the right, in the first half of the rotation when turning right to left near a wall, with the player's back facing the wall. In other words, I am getting the exact same result I already had. Nothing changed.
Last edited by Ruben; 02/21/18 03:13.
|
|
|
Re: Camera passing through wall
[Re: Ruben]
#471158
02/21/18 03:20
02/21/18 03:20
|
Joined: Jul 2014
Posts: 72
DriftWood
Junior Member
|
Junior Member
Joined: Jul 2014
Posts: 72
|
I see. Well great enjoy your hobby. It's impossible for *"Nothing changed" to change. It is possible that the change was too small. After all we moved the vecTarget so something change. So let's assume the change is just too small. Than try this.
vec_set( vecTarget, hit.x);
vec_set ( vec_temp, hit.nx);
vec_normalize ( vec_temp, 555);// Huge change
vec_add ( vecTarget, vec_temp);
If you still see no change something else is happening. If you see a big change, than adjust 555 down until close to correct. I also don't understand this lerp
vec_lerp ( camera.x, camera.x, vecTarget, time_step );]
The value of Time_step is a small decimal. It's not collecting or adding to anything or itself. This could be a your big problem. Try
..............
var range = 0;
.............
if(Taget_hit)
{
.........
if (range < 1)
range += time_step;
}
else
{
.....
range = 0;
}
vec_lerp ( camera.x, camera.x, vecTarget, range );]
I would like you to understand, I don't use this engine, I haven't in over a year. I don't have this engine installed and I work from memory, logic and looking in the manual to answer your questions. Finally I get nothing out of helping you, I answer for your benefit, my involvement is volunteer and I can stop if it's not to you're taste. We all have jobs or other things to take our time. I currently am working on a project in another community and also learning a second engine, so my free time has other things to fill it than answering here.
Last edited by DriftWood; 02/21/18 03:59.
|
|
|
Re: Camera passing through wall
[Re: DriftWood]
#471161
02/21/18 04:12
02/21/18 04:12
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
I see. Well great enjoy your hobby. It's impossible for *"Nothing changed" to change. It is possible that the change was too small. After all we moved the vecTarget so something change. So let's assume the change is just too small. Than try this.
vec_set( vecTarget, hit.x);
vec_set ( vec_temp, hit.nx);
vec_normalize ( vec_temp, 555);// Huge change
vec_add ( vecTarget, vec_temp);
If you still see no change something else is happening. If you see a big change, than adjust 555 down until close to correct. I also don't understand this lerp
vec_lerp ( camera.x, camera.x, vecTarget, time_step );]
The value of Time_step is a small decimal. It's not collecting or adding to anything or itself. This could be a your big problem. Try
..............
var range = 0;
.............
if(Taget_hit)
{
.........
if (range < 1)
range += time_step;
}
else
{
.....
range = 0;
}
vec_lerp ( camera.x, camera.x, vecTarget, range );]
I would like you to understand, I don't use this engine, I haven't in over a year. I don't have this engine installed and I work from memory, logic and looking in the manual to answer your questions. Finally I get nothing out of helping you, I answer for your benefit, my involvement is volunteer and I can stop if it's not to you're taste. We all have jobs or other things to take our time. I currently am working on a project in another community and also learning a second engine, so my free time has other things to fill it than answering here. I apologize. I really do sincerely appreciate your help. I am realizing that your code actually does work. I am just seeing blue on the right half of the camera before the HIT_TARGET is activated in the exact middle of the camera, and once it is activated, the camera is pushed inside the wall using your code, as it needs to do. So, thank you. Thanks to you, the code is working as it should after the HIT_TARGET is activated. Now I am trying to make it so that the:
var distance = c_trace ( player.x, vecTarget, IGNORE_ME |
IGNORE_PASSABLE | IGNORE_SPRITES | USE_POLYGON );
...before the HIT_TARGET call makes collision on the right side of the camera, instead of its dead center. It seems to me that collision is happening only in the middle of the camera, instead of the actual side of the camera, making it so that the camera's right half peeks past the wall, until the wall hits center on the camera lens, then collision happens, and activates your code. I am trying to figure out how to make collision happen on the right side of the camera, so that I do not have to see the blue at all when turning the player's back toward the wall. I will try to use your logic before the HIT_TARGET call to make the same thing happen before that call, as it does after.
Last edited by Ruben; 02/21/18 04:15.
|
|
|
Re: Camera passing through wall
[Re: Ruben]
#471163
02/21/18 05:54
02/21/18 05:54
|
Joined: Jul 2014
Posts: 72
DriftWood
Junior Member
|
Junior Member
Joined: Jul 2014
Posts: 72
|
Here is my best attempt from my mobile. Two extra traces from camera left and right.
if ( HIT_TARGET )
{
vec_set ( vecTarget, hit.x );
vec_set( vecTarget, hit.x);
vec_set ( vec_temp, hit.nx);
vec_normalize ( vec_temp, 20);
vec_add ( vecTarget, vec_temp);
if ( distance > 0 )
reset ( me, TRANSLUCENT );
else
set ( me, TRANSLUCENT );
}
else
{
// CREATE A SIDE VECTOR FROM CAMERA
vec_set(vec_temp,vector(0,20,0));
// ROTATE TO BY CAM PAN AND ADD CAM VEC
vec_rotate ( vec_temp, vector(camera.pan,0,0) );
vec_add ( vec_temp camera.x );
// YOUR CODE
reset ( me, TRANSLUCENT );
// TRACE SIDEWAYS FROM CAMERA
distance = c_trace ( camera.x, vec_temp, IGNORE_ME |
IGNORE_PASSABLE | IGNORE_SPRITES |
USE_POLYGON | IGNORE_MODELS );
//CHECK HIT
if(HIT_TARGET)
{
/* ANOTHER WAY
// SET DISTANCE INTO TEMP.Y ( POS trace = NEG Distance
vec_set( vec_temp, vector(0,-distance,0));
// ROTATE BY CAM PAN
vec_rotate(vec_temp, vector (camera.pan,0,0);
// ADD TO VecTarget ** because it's already available
vec_add(vecTarget, vec_temp); */
vec_set ( vec_temp, hit.nx);
vec_normalize ( vec_temp, 20);
vec_add ( vecTarget, vec_temp);
}
// REPEAT FOR LEFT TRACE !!!
// CREATE A SIDE VECTOR FROM CAMERA ** CHANGE TO NEG VEC
vec_set(vec_temp,vector(0,-20,0));
// ROTATE TO BY CAM PAN AND ADD CAM VEC
vec_rotate ( vec_temp, vector(camera.pan,0,0) );
vec_add ( vec_temp camera.x );
// TRACE SIDEWAYS FROM CAMERA
distance = c_trace ( camera.x, vec_temp, IGNORE_ME |
IGNORE_PASSABLE | IGNORE_SPRITES |
USE_POLYGON | IGNORE_MODELS);
//CHECK HIT
if(HIT_TARGET)
{
/* // SET DISTANCE INTO TEMP.Y (*! NEG trace = POS Distance
vec_set( vec_temp, vector(0,distance,0));
// ROTATE BY CAM PAN
vec_rotate(vec_temp, vector (camera.pan,0,0);
// ADD TO VecTarget ** because it's already available
vec_add(vecTarget, vec_temp); */
vec_set ( vec_temp, hit.nx);
vec_normalize ( vec_temp, 20);
vec_add ( vecTarget, vec_temp);
}
}
// REMOVED
//vec_lerp ( camera.x, camera.x, vecTarget, time_step );
vec_set(camera.x, vecTarget);
vec_sub ( vecOrigin, camera.x );
vec_to_angle ( camera.pan, vecOrigin );
}
BTW vec_scale messes up the direction it should also be vec_nornalize
VECTOR vecTarget;
vec_for_angle ( vecTarget, my.skNextPan );
// vec_scale ( vecTarget, -80 );
vec_normalize( vecTarget, -80);
Bonus homework - vec_scale and vec_normalize both multiply the elements of a vector. So find out what is the difference and why it is important.
Last edited by DriftWood; 02/21/18 06:20.
|
|
|
Re: Camera passing through wall
[Re: DriftWood]
#471173
02/21/18 12:30
02/21/18 12:30
|
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
|
That workaround fails when the view ray is nearly parallel to a surface the camera ends close to and the c_trace did not collide to. The only solution I know is the use of a dummy entity and USE_BOX in the trace.
action actCameraCollider () {
proc_mode = PROC_LATE; // execute after player action
my->flags |= INVISIBLE | PASSABLE | FAT | NARROW;
vec_set(&my->max_x, vector(16, 16, 16)); // collision hull
vec_set(&my->min_x, vector(-16, -16, -16));
VECTOR vOffset;
vec_set(&vOffset, vector(0, -7, 35)); // camera rotation center in player space
var nCamDist = 200; // distance to the center
...
vec_set(&my->x, &vOffset); // set the collider position in reference to the player position and orientation
vec_rotate(&my->x, &player->pan);
vec_add(&my->x, &player->x);
VECTOR vDir;
vec_for_angle(&vDir, &camera->pan); // compute the inverse of the view ray; the trace is backwards
vec_scale(&vDir, -nCamDist);
VECTOR vTarget; // compute the target position for c_trace
vec_set(&vTarget, &my->x); // it is also the final camera position when the trace collides nothing
vec_add(&vTarget, &vDir);
you = player;
var nDist = c_trace(&my->x, &vTarget, IGNORE_YOU | IGNORE_PASSABLE | USE_BOX);
if (nDist > 0) { // when it collides
vec_normalize(&vDir, nDist); // enshort the view ray
vec_set(&camera->x, &my->x); // and recompute the position of the camera
vec_add(&camera->x, &vDir);
} else { // when it does not collide
vec_set(&camera->x, &vTarget); // set the already computed position of the camera
}
...
Salud!
|
|
|
Re: Camera passing through wall
[Re: txesmi]
#471176
02/21/18 16:06
02/21/18 16:06
|
Joined: Jul 2014
Posts: 72
DriftWood
Junior Member
|
Junior Member
Joined: Jul 2014
Posts: 72
|
@Ruban txesmi presents the best solution and far better code( always) than I do. Take his advice. I do reference you to my prior post which I suggest camera in a box. Txesmi presents the end evolution of using an invisible box entity for camera collision. @txesmi you're still the best under the sun!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|