Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (TipmyPip, AndrewAMD, dBc), 18,430 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Code to show model outline through obstacles? Slow cam rotation? #440778
05/01/14 22:13
05/01/14 22:13

T
tolu619
Unregistered
tolu619
Unregistered
T



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.

Code:
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:

Code:
camera_follow(me);


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

T
tolu619
Unregistered
tolu619
Unregistered
T



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: ] #440865
05/04/14 21:39
05/04/14 21:39
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
you could simply do a trace to check to see if the player is visible or not, and if not then you can apply znear and a shader combined to get this effect, I think this could work laugh


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: Code to show model outline through obstacles? Slow cam rotation? [Re: DLively] #440871
05/05/14 00:07
05/05/14 00:07

T
tolu619
Unregistered
tolu619
Unregistered
T



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: ] #440874
05/05/14 05:42
05/05/14 05:42
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Well you could also set him to Translucent - but a shader would ultimatly look wayy better wink


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: Code to show model outline through obstacles? Slow cam rotation? [Re: ] #440875
05/05/14 06:01
05/05/14 06:01
Joined: Jul 2007
Posts: 620
Turkey, Izmir
Emre Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 620
Turkey, Izmir
The commented part completly wrong. it should be like that;
Code:
c_trace....
if(HIT_TARGET)
{
	if (hit.entity!=ent)
	{
		set(hit.entity, TRANSLUCENT);
		hit.entity.alpha = 60;
	}
}


Re: Code to show model outline through obstacles? Slow cam rotation? [Re: Emre] #440887
05/05/14 11:11
05/05/14 11:11

T
tolu619
Unregistered
tolu619
Unregistered
T



Originally Posted By: Emre
The commented part completly wrong. it should be like that;
Code:
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 Offline
User
Emre  Offline
User

Joined: Jul 2007
Posts: 620
Turkey, Izmir
Originally Posted By: tolu619

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...

Code:
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

T
tolu619
Unregistered
tolu619
Unregistered
T



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 Offline
Expert
sivan  Offline
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.

Free world editor for 3D Gamestudio: MapBuilder Editor
Page 1 of 2 1 2

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1