Gamestudio Links
Zorro Links
Newest Posts
Get a csv file into an array of structs, confused about lite-c
by easyX
6 minutes 32 seconds ago
Random walk vs Real price statistic
by kujo
Yesterday at 21:40
Inline functions in Lite-C
by MasterQ32
Yesterday at 21:04
Alpha Vantage API key - where to put?!
by veepsirtt
Yesterday at 10:26
Using standard C libraries with Zorro?
by Hredot
Yesterday at 02:51
AssetVars in Asset Lists
by Hredot
Yesterday at 02:50
How to count
by brax
02/17/18 20:15
AUM Magazine
Latest Screens
Forgotten Tales - Demo version
RPG PARTY
Triton Wing now available on Steam
AckCon'17: Lotter vs The World
Who's Online
21 registered (easyX, Hredot, kujo, alibaba, AndrewAMD, Kartoffel, DASFX, boatman, 4 invisible), 458 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
veepsirtt, trulala, elninio, Thwessen23, rmassip
17890 Registered Users
Topic Options
Rate This Topic
#470947 - 02/14/18 08:29 Camera passing through wall
Ruben Offline
User

Registered: 06/11/10
Posts: 562
Loc: California
I am trying to make it so that if the player moves near a wall, and turns its back toward it while turning its body, the camera following the player will glide along the inside of the wall, pushing itself closer to the player's back, and then backs up to its normal following distance once the player's back is turned away from the wall.

I have a function that mostly does this. However, for some reason, while the player is turning its body while facing its front away from the wall (back toward wall), the camera will go behind the wall for the first 90 degrees on the left side of the turn instead of gliding on the inside of the wall, staying at the same distance behind the player as it would have with no collision detected, but then for the second 90 degrees of the turn on the right, the camera will start doing what I want it to do by gliding on the inside of the wall coming closer to the player's back for the remainder of the turn. It is always the first 90 degrees on the left side of the turn where the camera goes through the wall behind the player (what I do NOT want to happen), and always the second 90 degrees on the right of that same turn where the camera does not go through the wall and instead glides on the inside of the wall (what I would like to happen for the whole 180 degrees of this turn). This happens in the exact same manner from left to right, no matter what the wall, no matter where the wall is.

Here is my camera function:

Code:
void _handle_cam_3rdperson()
{
   c_rotate ( me, vector(-mickey.x * 0.3, 0, 0), IGNORE_ME |
              IGNORE_PASSABLE | IGNORE_SPRITES | USE_POLYGON |
              GLIDE );
		
   my.skNextPan = my.pan;
	
   my.skNextTilt = clamp ( my.skNextTilt - mickey.y * 0.3, 
                              -90, 90 );
   my.skNextRoll = 0; 
	
   VECTOR vecOrigin;	
			
   vec_set ( vecOrigin, vector(5,-25,40) ); 
   vec_rotate ( vecOrigin, vector(my.pan,0,0) ); 
   vec_add ( vecOrigin, my.x ); 	

   VECTOR vecTarget;
   vec_for_angle ( vecTarget, my.skNextPan );
	
   vec_scale ( vecTarget, -80 );
	
   vec_add ( vecTarget, vecOrigin );

   // THIS SEEMS TO BE WHERE THE ERROR LIES		
   var distance = c_trace ( vecOrigin, vecTarget, IGNORE_ME |
                            IGNORE_PASSABLE | IGNORE_SPRITES |
                            USE_POLYGON ); 
	
   if ( HIT_TARGET )
   {
      beep(); // THIS BEEPS DURING THE 2ND 90 DEGREES OF THE TURN IN
              //    QUESTION, NOT DURING THE 1ST 90 DEGREES.

      vec_set ( vecTarget, hit.x );
		
      if ( distance > 0 )
         reset ( me, TRANSLUCENT );
      else
         set ( me, TRANSLUCENT );
   
   }
   else
   {
      reset ( me, TRANSLUCENT );
   }
		
   vec_lerp ( camera.x, camera.x, vecTarget, time_step );
		
   vec_sub ( vecOrigin, camera.x );
   vec_to_angle ( camera.pan, vecOrigin );
}


It appears that this line of code is causing the error in question:

Code:
var distance = c_trace ( vecOrigin, vecTarget, IGNORE_ME |
                         IGNORE_PASSABLE | IGNORE_SPRITES |
                         USE_POLYGON );


The beep() right after the HIT_TARGET beeps like crazy during the 2nd 90 degrees of the turn sensing the collision, but does not beep at all during the 1st 90 degrees of the turn which shows that collision is not being detected. Why is the c_trace line from vecOrigin and vecTarget not being detected during the first 90 degrees of the turn, but is being detected during the second 90 degrees of the same turn?

Any help will be greatly appreciated. Thank you.


Edited by Ruben (02/16/18 04:31)

Top
#471014 - 02/16/18 06:21 Re: Camera passing through wall [Re: Ruben]
Ruben Offline
User

Registered: 06/11/10
Posts: 562
Loc: California
Okay, made a little progress. I find that altering the xyz coordinates in:
Code:
vector(5,-25,40)


...for this code:
Code:
vec_set ( vecOrigin, vector(5,-25,40) );


...is changing the location of the c_trace line, and making the first part of the turn where the camera is behind the wall last shorter (like maybe first 30 degrees of turn), and more quickly start gliding inside the wall like I want it to (for about the last 110 degrees of the turn). Only thing is that I have to permanently change the camera position to accomplish this. It might work great for turning player with its back facing a wall, but when the player's back faces away from the wall, the camera is not in a position that I want it to be in.

Trying to make it so that the camera does not go through a wall when facing player's back against it during a turn, and also having the camera be where I want it to be when the player's back is facing away from a wall as well.


Edited by Ruben (02/16/18 06:23)

Top
#471015 - 02/16/18 06:50 Re: Camera passing through wall [Re: Ruben]
DriftWood Offline
Junior Member

Registered: 07/03/14
Posts: 54
Very old engine means every simple thing is solved already on forum or...
http://opserver.de/twik11/index.php?title=Main_Page
Slin did this 8 years ago
http://opserver.de/twik11/index.php?title=Improved_3rd_Person_Camera
I think superku has done another one.
Then there is always
http://www.coniserver.net/coni_users/web_users/pirvu/aum/aumonline_e/

Top
#471045 - 02/17/18 05:05 Re: Camera passing through wall [Re: DriftWood]
Ruben Offline
User

Registered: 06/11/10
Posts: 562
Loc: California
Thank you Driftwood. I will check it out.

Top



Gamestudio download | chip programmers | Zorro platform | shop | resources | magazine | manual | support faq | bugs

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) 3dgamestudio.net