1 registered members (AndrewAMD),
1,403
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How do I make the camera stay inside the walls?
#276986
07/07/09 10:12
07/07/09 10:12
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
I am trying out a camera code that I found in the Aums. How do I stop the camera from going outside the walls of a house? I only whant it to stay inside , because now when the player are to close to a wall the camera goes outside....and then I cant see the player....
if (camera_number == 3) // isometric view
{
camera.x = player.x - 350 * cos(player.pan); // 200 = distance
camera.y = player.y - 350 * sin(player.pan); // same value here
camera.z = player.z + 200; // above the player 200
camera.pan = player.pan;
camera.tilt = -30; // look down at the player -30
camera.roll = 0;
}
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
Re: How do I make the camera stay inside the walls?
[Re: Cowabanga]
#277006
07/07/09 11:34
07/07/09 11:34
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
No camera.clip_near = 0; didnt work. Did even try to put it inside my cameracode.
I start the game inside a hollow box (that is the house). And when I turn the player when it stands close to the wall, the camera goes outside the box and I cant see the player.... only see the other 3 walls and floor.
Last edited by Eagelina; 07/07/09 11:35.
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
Re: How do I make the camera stay inside the walls?
[Re: VeT]
#277008
07/07/09 11:36
07/07/09 11:36
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
@VeT Yes that is what I am looking for. A way to force the camera to stay inside al the time.... Sorry for asking but can you write a "fake/psedo" code to show what you mean. I read code better than text....
Last edited by Eagelina; 07/07/09 11:38.
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
Re: How do I make the camera stay inside the walls?
[Re: Eagelina]
#277012
07/07/09 11:52
07/07/09 11:52
|
Joined: Aug 2004
Posts: 1,345 Kyiv, Ukraine
VeT
Serious User
|
Serious User
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
|
Here is example of code that you need: http://www.gstools.de/aum/aum82/questions_from_the_forum.htmfunction avoid_obstacles()
function avoid_obstacles()
{
vec_set (temporary_distance.x, camera.x);
temporary_distance.z -= 50; // sets a position closer to the feet of the player; 50 = experimental value
distance_traced = c_trace (player.x, temporary_distance.x, IGNORE_ME | IGNORE_PASSABLE); // trace between the player and temporary_distance
if (distance_traced == 0) // no obstacles on the way?
{
my.alpha = minv(100, my.alpha + 3 * time_step); // then increase player's alpha up to 100
if (player.alpha == 100)
{
reset(player, TRANSLUCENT);
}
else
{
set(player, TRANSLUCENT);
}
if (camera_distance < my.skill40) // if the camera got closer to the player
{
camera_distance += 1; // restore the initial camera_distance slowly
}
}
else // obstacles encountered?
{
distance_traced -= 2; // then bring the camera 2 quants closer to the player!
my.alpha = (distance_traced / (my.skill40 + 1)) * 100; // decrease player's alpha; don't allow a division by zero
camera.x = player.x - distance_traced * cos(camera.pan); // place the camera behind the player
camera.y = player.y - distance_traced * sin(camera.pan); // at the new distance given by distance_traced
}
}
|
|
|
Re: How do I make the camera stay inside the walls?
[Re: VeT]
#277025
07/07/09 12:26
07/07/09 12:26
|
Joined: Mar 2006
Posts: 321 Norway
Eagelina
OP
Senior Member
|
OP
Senior Member
Joined: Mar 2006
Posts: 321
Norway
|
Yes thats the code from the morrowin .... And now I understand. Thanks
A6 and A7 Commercial ------------------- Programmer always searching for more to learn and understand.
|
|
|
|