Gamestudio Links
Zorro Links
Newest Posts
Performance reporting showing Annual and monthly % returns
by OptimusPrime
Today at 01:19
Issue with inconsistent test results
by kvm
Yesterday at 17:24
Access string content through another string
by ChrstphFr
Yesterday at 11:30
How to return a vector from a function
by Superku
Yesterday at 05:39
Vector Displacement, realtime Blendshapes
by jumpman
08/14/18 23:46
Code Repository
by OptimusPrime
08/14/18 13:25
Votes for future features
by OptimusPrime
08/14/18 07:18
AUM Magazine
Latest Screens
AckCon'18 - Lotter vs the World 2 - Preview Release
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Forgotten Tales - Demo version
Who's Online
6 registered (Dalla, kvm, jenGs, firecrest, alibaba, bailemad), 452 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
Ulenspegel, toto, FloMi, behr065, OptimusPrime
18027 Registered Users
Page 1 of 3 1 2 3 >
Topic Options
Rate This Topic
#470947 - 02/14/18 08:29 Camera passing through wall
Ruben Offline
User

Registered: 06/11/10
Posts: 587
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: 587
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: 72
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: 587
Loc: California
Thank you Driftwood. I will check it out.

Top
#471113 - 02/20/18 02:02 Re: Camera passing through wall [Re: Ruben]
Ruben Offline
User

Registered: 06/11/10
Posts: 587
Loc: California
So, it seems I made some progress. I changed this code:
Code:
var distance = c_trace ( vecOrigin, vecTarget, IGNORE_ME |
                            IGNORE_PASSABLE | IGNORE_SPRITES |
                            USE_POLYGON );


...to this:
Code:
var distance = c_trace ( player.x, vecTarget, IGNORE_ME |
                            IGNORE_PASSABLE | IGNORE_SPRITES |
                            USE_POLYGON );


The beep() just after the HIT_TARGET now beeps whenever the camera touches the wall (which is great), and the camera does not go behind the wall (which is also great), at least not entirely (which still gives me an issue).

The issue is, lets say you are the player, and your player's front side is facing a wall. You move your mouse left, making the player rotate left. The camera rotates with and behind the player, facing the player's back at all times, all while the right side of the camera moves closer toward the wall given that the player is rotating. The camera's right side makes contact with the wall, and glides along the wall, making it move closer to the player's back as the player keeps rotating, all the way till the player rotates so far to the point that its back is not facing the wall anymore, at which point the camera detaches from the wall and moves back to its original distance behind the player.

In the first half of this rotation where the camera makes contact with the wall, I can see a vertical sliver of blue on the right side of the screen past the wall (which is not great). The camera is not entirely moving through the wall like before, but it feels like a small section on the right side of the camera is peeking through the wall, as the camera glides along the wall. Once the camera reaches the middle of the rotation, making the camera face directly away from the wall and toward the player's back, the blue disappears (which is great). Once the camera reaches the opposite side of this same rotation, no blueness is present at all (which is great). This gives the feeling like the right side of the camera peeks through the wall, and the left side of the camera does not.

Does anyone have a clue on how to prevent the camera from peeking past the wall for the entire rotation, while the player's back is facing the wall?


Edited by Ruben (02/20/18 02:52)

Top
#471118 - 02/20/18 04:03 Re: Camera passing through wall [Re: Ruben]
DriftWood Offline
Junior Member

Registered: 07/03/14
Posts: 72
The solution is to move the camera further away from the wall.

I don't read 3dgs code perfectly anymore.
Ok you seem to be placing the camera right at hit.x or in other words *on the surface of the wall.*

My solution would be to simply move vecTarget closer to the player after the set . Assume the camera has a size of 20.

Vec_set(vecTarget,hit.x)
**Now adjust the vec say 20 closer to the player.
Get the Vector from vecTarget to the player.
Normalize it to 20.
Then vec_add it to vecTarget ?? Or is vec_sub I forget.
Bam! Camera has extra room and is off the surface of the wall.
So I'll have to look at the manual and remember how to do that.


Edited by DriftWood (02/20/18 04:04)

Top
#471119 - 02/20/18 04:17 Re: Camera passing through wall [Re: DriftWood]
DriftWood Offline
Junior Member

Registered: 07/03/14
Posts: 72
I'm guessing something like this.
Code:
Vec_set ( vecTarget, hit.x);
Vec_set (temp_vecA, player.x);
Vec_set (temp_vecB, vecTarget);
Vec_sub (temp_vecA, temp_vecB);
Vec_nomalize(temp_vecA, 20);
Vec_add (vecTarget, temp_vecA);
//Now vecTarget "should be" 20 units off the wall and closer to the player.


Other solutions could be putting the camera in abox. Using side traces from the camera. Using 3 traces to the wall and blending the vecTarget further to the open side. Or hiring a virtual monkey to fly the camera in the dangerous isolation of 3dgs space!!!

Top
#471120 - 02/20/18 04:29 Re: Camera passing through wall [Re: DriftWood]
DriftWood Offline
Junior Member

Registered: 07/03/14
Posts: 72
Wait!!! Cool idea! Why not just push off the wall using it's own normal?!
Yeah that could work!
Code:
Vec_set( vecTarget, hit.x);
Vec_set ( vec_temp, hit.nx);
Vec_normalize ( vec_temp, 20);
Vec_add ( vecTarget, vec_temp);
// Bam!!! Virtual Monkey!!!


Top
#471121 - 02/20/18 04:34 Re: Camera passing through wall [Re: DriftWood]
DriftWood Offline
Junior Member

Registered: 07/03/14
Posts: 72
Virtual Monkey freezes and dies in the cold frigid isolation of A8 3dgs space.
Alone and sad his body floats away.

But good news!
Aliens clone virtual monkey and resurrect him in another engines!!
He's saved and happy.

Top
#471126 - 02/20/18 09:42 Re: Camera passing through wall [Re: DriftWood]
Ruben Offline
User

Registered: 06/11/10
Posts: 587
Loc: California
Originally Posted By: DriftWood
Wait!!! Cool idea! Why not just push off the wall using it's own normal?!
Yeah that could work!
Code:
Vec_set( vecTarget, hit.x);
Vec_set ( vec_temp, hit.nx);
Vec_normalize ( vec_temp, 20);
Vec_add ( vecTarget, vec_temp);
// Bam!!! Virtual Monkey!!!


Interesting, I never heard of ".nx". I cannot seem to find it in the manual, or online. Where does it discuss the concept of ".nx"?*

Top
Page 1 of 3 1 2 3 >



Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

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