2 registered members (TipmyPip, AndrewAMD),
14,136
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
3rd Person Camera Ground Level
#141326
07/16/07 02:21
07/16/07 02:21
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
Hey,
This may be a trivial problem, but I can't seem to get it to work out for me..
I have written my own 3rd person camera system, and I need to detect the z-value of the ground below the camera. This way, I can move the camera a set distance above the ground to avoid the camera going under the terrain.
I had tried using c_trace like I had done with my player, but I think I was missing something because the camera behaved sporadically.
It's been stumping me for a little while now, so I'm just hoping that a more seasoned coder than myself could help me out.
Thanks,
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: 3rd Person Camera Ground Level
[Re: mbartman]
#141327
07/16/07 03:15
07/16/07 03:15
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
I figured it out, I just needed to create a temporary vector to represent the camera position.. That seems to be too jumpy though...
Back to the drawing board I suppose..
Thanks,
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: 3rd Person Camera Ground Level
[Re: mbartman]
#141328
07/16/07 10:56
07/16/07 10:56
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
c_trace sounds like a good way to go  could u post us a snippet so we might be able to figure out how to smoothen it for you? julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: 3rd Person Camera Ground Level
[Re: JibbSmart]
#141329
07/16/07 18:43
07/16/07 18:43
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
Code:
int cam_height = 100;
VECTOR ground; VECTOR temp_cam; vec_zero(ground); vec_zero(temp_cam);
temp_cam.x = camera.x; temp_cam.y = camera.y;
vec_set(ground, temp_cam.x); ground.z -= 10000; trace_mode = IGNORE_ME + IGNORE_PASSABLE + USE_BOX; ground.z = -c_trace(temp_cam.x,ground,trace_mode);
camera.z = ground.z + cam_height;
I think that the reason it's jumpy is because the height of the terrain changes sporadically depending on the slope and even though I am setting USE_BOX the camera isn't very 'fat.' So if there was some way I could make the camera 'fatter' so that it's collision box would be bigger, I think that that would help. Thanks for your reply  ,
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: 3rd Person Camera Ground Level
[Re: mbartman]
#141330
07/16/07 20:53
07/16/07 20:53
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
i think USE_BOX depends on the bounding box of the entity calling the c_trace, so if this is called by another entity (whoever the "my" pointer points to), the box will be based on that entity's shape. if it is a standalone function with no "my" pointer -- well, the camera doesn't have a bounding box afaik. you could get the difference between the camera's current z and its new z, and average it out. this way, the camera should smoothly move between the different heights instead of instantly going to the new height. hope this helps  julz
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: 3rd Person Camera Ground Level
[Re: JibbSmart]
#141331
07/16/07 22:10
07/16/07 22:10
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
That just might work, I'll try to work on that as soon as I get a chance, and I'll post a snippet if I get it to work out properly. Thanks a lot for your input, I think it may have been just what I needed 
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
Re: 3rd Person Camera Ground Level
[Re: mbartman]
#141332
07/17/07 04:01
07/17/07 04:01
|
Joined: Jan 2007
Posts: 63 Oregon
mbartman
OP
Junior Member
|
OP
Junior Member
Joined: Jan 2007
Posts: 63
Oregon
|
Code:
var cam_height = 350;
VECTOR temp_ground; VECTOR temp_cam;
vec_zero(temp_ground); vec_zero(temp_cam);
temp_cam.x = camera.x; temp_cam.y = camera.y;
vec_set(temp_ground, temp_cam.x);
temp_ground.z -= 10000;
trace_mode = IGNORE_ME + IGNORE_PASSABLE;
temp_ground.z = c_trace(temp_cam.x,temp_ground,trace_mode);
if((temp_ground.z + cam_height) != camera.z) { if(camera.z < (temp_ground.z + cam_height)) { camera.z += (5 * time_step); if(camera.z > (temp_ground.z + cam_height)) camera.z = temp_ground.z + cam_height; } else { camera.z -= (5 * time_step); if(camera.z < (temp_ground.z + cam_height)) camera.z = temp_ground.z + cam_height; } }
It works  Thanks for your idea!!
Michael Bartman
A6/A7 Commercial Edition
Programmer By Nature
|
|
|
|