Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, juanex), 1,247 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19056 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Camera glide along walls? #424436
06/16/13 00:41
06/16/13 00:41
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
I am trying to make the camera that follows behind my player character not go behind walls. For example, lets say I rotate my character next to a wall (with the camera behind the character, facing where the character is facing). Instead of moving along the wall and constantly viewing the character's back (even closing up to the character's back if need be), the camera goes behind the wall instead, so that I cannot see my character's back, or where the character is facing; only the other side of the wall that my character is next to.

Does anyone know of a function or technique to have the camera behind the character move along walls as the character turns, instead of go through them, so that I can always see character's back and facing direction at all times?

Re: Camera glide along walls? [Re: Ruben] #424437
06/16/13 00:59
06/16/13 00:59
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You have already asked this question in another forum and you even got some replies:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=424401#Post424401

Have you tried to code one of the suggested approaches? If yes, where do/ did you encounter problems? Post your code.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Camera glide along walls? [Re: Superku] #424438
06/16/13 01:16
06/16/13 01:16
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Originally Posted By: Superku
You have already asked this question in another forum and you even got some replies:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=424401#Post424401

Have you tried to code one of the suggested approaches? If yes, where do/ did you encounter problems? Post your code.

In order to trace, I would assume c_trace is the only function to use, unless I am mistaken. In order to use c_trace, don't you need two vertices to create the c_trace beam?

Okay, I can find a vertex on my player character by opening up MED. But what about the camera that is following my character? How can I find a vertex on the camera following my character in order to complete the c_trace beam?

Here is my code for the camera following my character:

Code:
function camera_follow(ENTITY* ent)
{
	while(1) 
	{
		vec_set(camera.x,vector(-200,-35,45));  //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,-5,0)); // look in player direction, slighty down      


		wait(1);
	}
}


How would I find the vertex for the camera from this code, or do I really need the vertex of the camera to do the c_trace?

Last edited by Ruben; 06/16/13 01:21.
Re: Camera glide along walls? [Re: Ruben] #424439
06/16/13 01:40
06/16/13 01:40
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Normally you don't use vertices when dealing with c_trace (or any other function), I assume in your case you simply grab the position (!!) of two vertices and use this, not the vertices themselves.
The function prototype for c_trace reads as follows:
c_trace(VECTOR* from, VECTOR* to, var mode)

You only need to have or calculate two positions. This could be done as follows - the code is untested, but it should give you the right idea:

Code:
function camera_follow(ENTITY* ent)
{
	var camera_distance, camera_distance_max;
	VECTOR camera_target;
	
	camera_distance_max = vec_length(vector(-200,-35,45));
	camera_distance = camera_distance_max;
	while(1) 
	{
		// calculate camera target
		vec_set(camera_target.x,vector(-200,-35,45));  //camera position relative to the player     
		vec_rotate(camera_target.x,ent.pan); // rotate the camera position with the player
		vec_add(camera_target.x,ent.x);      // add player position
		camera_distance += (camera_distance_max-camera_distance)*0.2*time_step; // for a smoother wall alignment
		
		// check for walls
		
		set(ent,PASSABLE);
		result = c_trace(ent.x,camera_target,IGNORE_PASSABLE);
		reset(ent,PASSABLE);
		if(trace_hit) camera_distance = minv(camera_distance,result);
		
		// set camera position
		
		vec_lerp(camera.x,ent.x,camera_target.x,camera_distance/camera_distance_max);
		vec_set(camera.pan,vector(ent.pan,-5,0)); // look in player direction, slighty down      

		wait(1);
	}
}



EDIT: If the camera still looks through walls, try to replace
if(trace_hit) camera_distance = minv(camera_distance,result);
with
if(trace_hit) camera_distance = minv(camera_distance,result-32);
or any other negative value.

Last edited by Superku; 06/16/13 01:43.

"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Camera glide along walls? [Re: Superku] #424440
06/16/13 02:49
06/16/13 02:49

M
Malice
Unregistered
Malice
Unregistered
M



Wow Superku that is real great. Good to see how to use all those vector instructions I've never learned. I had to look up vec_lerp() lol.

Is there a speed advantage to the set/reset PASSABLE over IGNORE_ME ? I don't understand why you did it.

I don't mean to hijack I'm just assuming that if I got confused then the OP might have as well. (Ok I really wanted to know wink )

By-the-way THANK YOU Superku for my new camera obstacle base code.

Last edited by Malice; 06/16/13 02:57.
Re: Camera glide along walls? [Re: ] #424441
06/16/13 03:19
06/16/13 03:19
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Haha no problem, you are welcome!

Yes, there is a reason for not using IGNORE_ME. Imagine you call the function with
camera_follow(player);
from anywhere where my is NULL (f.i. the main function) or from any other entity that is not the player) instead of
camera_follow(my);,
then the code (on IGNORE_ME basis) will most likely not work correctly because the my pointer points to the wrong entity.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Camera glide along walls? [Re: Superku] #424482
06/17/13 07:21
06/17/13 07:21
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Superku. Your code works great. I am still trying to grasp my head around the intricacies of how it works, but it works. Thank you.

Re: Camera glide along walls? [Re: Superku] #424491
06/17/13 08:10
06/17/13 08:10
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Originally Posted By: Superku
EDIT: If the camera still looks through walls, try to replace
if(trace_hit) camera_distance = minv(camera_distance,result);
with
if(trace_hit) camera_distance = minv(camera_distance,result-32);
or any other negative value.


I would suggest using an entity as camera collider instead of shorten the ray by a constant.

Code:
ENTITY *entCameraCollider;
function camera_collider_startup ()
{
   entCameraCollider = ent_create(CUBE_MDL,vector(0,0,-100000),NULL);
   vec_fill(entCameraCollider.max_x, 16);
   vec_fill(entCameraCollider.min_x, -16);
   set ( entCameraCollider, INVISIBLE ); 
}

function camera_follow(ENTITY* ent)
{
   ...
   // check for walls

   set(ent,PASSABLE);
   ENTITY *entMeOld = me;
   me = entCameraCollider; 
   result = c_trace( ent.x, camera_target, IGNORE_PASSABLE | USE_BOX );
   reset(ent,PASSABLE);
   me = entMeOld;
   if(trace_hit) camera_distance = minv(camera_distance,result);
		
   ...
}


Last edited by txesmi; 06/17/13 08:28.
Re: Camera glide along walls? [Re: txesmi] #424499
06/17/13 10:50
06/17/13 10:50
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
That works really good as well txesmi. I like the fact that if you get to close to the wall when using your code, you cannot see the other side of the wall at all when you rotate the player, and you actually go into first person point of view before ever seeing the other side of the wall. Thank you. This is all really good code.

Re: Camera glide along walls? [Re: Ruben] #424511
06/17/13 18:58
06/17/13 18:58
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
That was the trick wink


Gamestudio download | chip programmers | 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