1 registered members (TipmyPip),
18,038
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Code to show model outline through obstacles? Slow cam rotation?
#440778
05/01/14 22:13
05/01/14 22:13
|
tolu619
Unregistered
|
tolu619
Unregistered
|
In games like Mario Galaxy, whenever there is an obstacle such as a wall in between the player and the camera, the player's shadow or outline shows on the obstacle so that we can still tell exactly where we are and what we're doing. I'm guessing the code to do so would be fairly simple, but I just can't figure it out. Here is my existing camera code. The commented part is my failed attempt to achieve some sort of transparency on the wall when it comes between the player and the camera.
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-400,0,100)); // 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,-10,0)); // look in player direction, slighty down
// c_trace(camera.x, ent.x, IGNORE_ME | IGNORE_PASSENTS);
// while (you != ent)
// {
// set(your, TRANSLUCENT);
// your.alpha = 60;
// }
wait(1);
}
}
My second problem is that even when the player's pan angle changes just slightly, the camera follows. It's always perfectly behind the player. I want it to only start to follow if the player has turned more than 30 degrees to the left or right so that we get to see the player's side view sometimes and not just always his back view. To test my camera code, add this line to your player code:
Last edited by tolu619; 05/02/14 10:49. Reason: updated code
|
|
|
Re: Code to show model outline through obstacles? Slow cam rotation?
[Re: ]
#440860
05/04/14 19:00
05/04/14 19:00
|
tolu619
Unregistered
|
tolu619
Unregistered
|
I really didn't want to make a double post but this topic has been up for 3 days and no one has replied. Please, help!
|
|
|
Re: Code to show model outline through obstacles? Slow cam rotation?
[Re: DLively]
#440871
05/05/14 00:07
05/05/14 00:07
|
tolu619
Unregistered
|
tolu619
Unregistered
|
So just this one line of code......set(my, ZNEAR); I haven't learnt any shader programming yet. No way to do it without first learning to write shaders?
|
|
|
Re: Code to show model outline through obstacles? Slow cam rotation?
[Re: Emre]
#440887
05/05/14 11:11
05/05/14 11:11
|
tolu619
Unregistered
|
tolu619
Unregistered
|
The commented part completly wrong. it should be like that;
c_trace....
if(HIT_TARGET)
{
if (hit.entity!=ent)
{
set(hit.entity, TRANSLUCENT);
hit.entity.alpha = 60;
}
}
looks good but will it work for walls and other level features such as a terrain which isn't actually an entity? Then how do I undo the hit.entity.alpha once the player is no longer behind a wall? Can I create a pointer to map features (walls, terrain, etc) and work with that?
|
|
|
Re: Code to show model outline through obstacles? Slow cam rotation?
[Re: ]
#440889
05/05/14 12:12
05/05/14 12:12
|
Joined: Jul 2007
Posts: 620 Turkey, Izmir
Emre
User
|
User
Joined: Jul 2007
Posts: 620
Turkey, Izmir
|
Then how do I undo the hit.entity.alpha once the player is no longer behind a wall?
Try this code. it works fine with entity and terrain. I have no idea about level blcoks. sorry...
ENTITY* temp_ent;
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-400,0,100)); // 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,-10,0)); // look in player direction, slighty down
c_trace(camera.x, ent.x, IGNORE_ME | IGNORE_PASSENTS);
if(HIT_TARGET)
{
if (hit.entity!=NULL)
{
if(temp_ent!=NULL) // undo translucent for previous entity
{
reset(temp_ent,TRANSLUCENT);
temp_ent.alpha = 100;
}
temp_ent=hit.entity;//handle for previous entity
set(hit.entity,TRANSLUCENT);
hit.entity.alpha = 60;
}
}
else //if no target, undo translucent for previous entity
{
if(temp_ent!=NULL)
{
reset(temp_ent, TRANSLUCENT);
temp_ent.alpha = 100;
}
}
wait(1);
}
}
|
|
|
Re: Code to show model outline through obstacles? Slow cam rotation?
[Re: Emre]
#440892
05/05/14 12:29
05/05/14 12:29
|
tolu619
Unregistered
|
tolu619
Unregistered
|
Thanks! I'll try it out and let you know how it went
|
|
|
Re: Code to show model outline through obstacles? Slow cam rotation?
[Re: ]
#440967
05/07/14 21:05
05/07/14 21:05
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
I'm not sure transparency works for terrains, maybe only when they have only one skin... for your camera problem: you can use vec_lerp(vec_result, vec1, vec2, factor); to smooth its movement, okay also for angles I think. or smooth(value, factor); if only one var should be managed.
Last edited by sivan; 05/08/14 08:27.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|