How to confirm collision with level blocks?

Posted By: tolu619

How to confirm collision with level blocks? - 07/26/14 11:50

I'm working on a wall-running feature in a 3D game. When the player presses the button, the monster dashes forward. If he bumps into a wall, he should start his wall-run, otherwise he should continue in his normal state. I tried to use hit.nx so I could get the normal to the hit surface and rotate the monster's tilt to be parallel to that normal. The problem is hit.nx seems to only return a value if an entity was hit, but not if a level block was hit. That's exactly the opposite of what I'm trying to do.
A better way to go about this please?
Code:
if(my.state == 12) //Obilicleon Wall-Running
        {
        	while(key_enter || joy_3)
		    wait(1);
	       	
	       	while(my.state == 12)
	       	{
	       		while((dash<100) && WallRunning == 0)
	       		{
	       			dash += 10 * time_step;
	   		        my.animation = 75; //75% animation frame is run3
	   		        ent_animate(me, "run", my.animation, 0);
	   	            c_move(me, vector(dash*time_step, 0, 0), vector(0, 0, -distancedown), USE_POLYGON |IGNORE_PASSABLE);
	                if((dash > 100) && (hit.nx != 0))
	                {
	                	dash = 0; my.animation = 0; WallRunning = 1;
	                	my.roll += 90; //temporary. Will replace with code to orient model to normal of hit surface
	       	            CameraChaseWallRun(me);
	                }
	                else if((dash>100) && hit.nx == 0)
	                {my.state = 3;} //state that waits for button release before reverting to state 1
	                wait(1);
       			}
....rest of wall-run state code
	       	}

}

Posted By: DLively

Re: How to confirm collision with level blocks? - 07/26/14 14:15

Use a c_trace, and trace in front of the monster, if there is something withing the trace (ie a wall) then do the next set of steps.
Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/27/14 22:16

Right now, I'm using this code snippet but it returns a value whether or not I hit a wall
Code:
var wall;
wall = c_trace(my.x,vec_rotate(vector(100,0,0),my.pan),IGNORE_ME|IGNORE_PASSABLE|IGNORE_CONTENT|IGNORE_MODELS);


While we're at it, after using a c_trace, I want to store the pointer to hit. I can't use ENTITY* or something similar. Please what kind of variable can I store it in?
Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/27/14 22:47

I think EVENT_BLOCK is activated just by my entity's feet being in contact with the regular floor. I just tried this and I get a "met a wall" message every frame.
Code:
function ObilicleonWallRun()
{
	if(event_type == EVENT_BLOCK)
	{
		WallRunning = 1;
		printf("Met a wall");
	}
}



THEN WITHIN THE MONSTER'S ACTION CODE...
if(my.state == 12) //Obilicleon Wall-Running
        {
        	while(key_enter || joy_3)
		    wait(1);	
		    
	       	WallRunning = 0; dash = 0; my.z += 20;
	       	my.emask |= ENABLE_BLOCK;
	       	my.event = ObilicleonWallRun;
	       	
	       	while(my.state == 12)
	       	{
	       		while((dash<100) && WallRunning == 0)
	       		{
	       			my.red += 10; my.ambient = 100; my.lightrange = 100;
	       			dash += 12 * time_step;
	   		        my.animation = 75; //75% animation frame is run3
	   		        ent_animate(me, "run", my.animation, 0);
	   	            c_move(me, vector(dash*time_step, 0, 0), vector(0, 0, -distancedown), USE_POLYGON |IGNORE_PASSABLE | IGNORE_SPRITES);
	   	            
	   	            if((dash>100) && WallRunning == 0)
	   	            {
	   	            	my.red = 0; my.ambient = 0; my.lightrange = 0; my.state = 3;
   	            	} //leave wall-running state because he didn't meet a wall

....rest of wall-run code here assuming he doesn't leave the wall-running state
}


Posted By: DLively

Re: How to confirm collision with level blocks? - 07/28/14 02:59

Code:
var wall;
wall = c_trace(my.x,vec_rotate(vector(100,0,0),my.pan),IGNORE_ME|IGNORE_PASSABLE|IGNORE_CONTENT|IGNORE_MODELS);



The reason this will not work is because you are tracing 100 quants on the x axis, rather than in front of the entity itself.

In order to trace in front of the entity, you will need to use some trig first, and store it inside a VECTOR, and trace from my.x, to the VECTOR you've created.

As old as this AUM is, it covers basic trig to achieve what you will need in order to get the correct direction for your trace.

Also, you can check to see if your trace has hit something, like this:

Code:
result = c_trace(my.x, trace_distance.x, FLAGS);
if(result > 0){beep();}//Hit something



Originally Posted By: from the manual

> 0 Distance to the hit polygon of the target or of the next obstacle in the way.
<= 0 No polygon was hit.
Posted By: sivan

Re: How to confirm collision with level blocks? - 07/28/14 07:24

hi
a little "advertisement" again: in MapBuilder2.41's playertest01 script you can find a proper c-tracing that is used for avoiding collision errors on block borders, which is probably an engine issue. you can get from there the normals you need. (beside some basic walk/run/crouch/fall/shoot features)
Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/28/14 15:05

Originally Posted By: DLively
Code:
var wall;
wall = c_trace(my.x,vec_rotate(vector(100,0,0),my.pan),IGNORE_ME|IGNORE_PASSABLE|IGNORE_CONTENT|IGNORE_MODELS);



The reason this will not work is because you are tracing 100 quants on the x axis, rather than in front of the entity itself.

In order to trace in front of the entity, you will need to use some trig first, and store it inside a VECTOR, and trace from my.x, to the VECTOR you've created.

As old as this AUM is, it covers basic trig to achieve what you will need in order to get the correct direction for your trace.

Also, you can check to see if your trace has hit something, like this:

Code:
result = c_trace(my.x, trace_distance.x, FLAGS);
if(result > 0){beep();}//Hit something



Originally Posted By: from the manual

> 0 Distance to the hit polygon of the target or of the next obstacle in the way.
<= 0 No polygon was hit.


The code in that AUM looks like it would detect even entities. I only want to detect level blocks
Posted By: Superku

Re: How to confirm collision with level blocks? - 07/28/14 17:59

Please state again exactly what you have tried and what you want to achieve (wallrunning or the like currently is irrelevant, collision with X and ignore Y is the important thing).

This should be implemented with c_trace in player direction (vec_rotate, then vec_add for target position), at least I would not base this on movement collisions. You can use IGNORE_MODELS or whatever the flag is called if you only want to check for block collision.

If you want to save hit-information (~> PM) you can do that with for example a CONTACT struct - however, up until today I've never wanted or needed to do that.
Posted By: DLively

Re: How to confirm collision with level blocks? - 07/28/14 18:04

Quote:
The code in that AUM looks like it would detect even entities. I only want to detect level blocks


Its the Trig I was getting you to look into, and see how to set a vector in front of the entity, using Sin and Cos.
Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/28/14 22:51

Originally Posted By: DLively
Quote:
The code in that AUM looks like it would detect even entities. I only want to detect level blocks


Its the Trig I was getting you to look into, and see how to set a vector in front of the entity, using Sin and Cos.

Oh, thanks. That's actually quite useful
Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/29/14 00:14

Using the AUM 4 snippets that Dlively posted, I've written this code
Code:
action RightMarkerAction()
{
	set(my, PASSABLE);
	my.blue = 100;
	my.ambient = 100;
	my.lightrange = 200;
	while(1)
	{
		FrontRightPos.x = your.x + (50 * cos(your.pan)) + (50 * sin(your.pan));
	    FrontRightPos.y = your.y + (50 * sin(your.pan)) - (50 * cos(your.pan));
	    FrontRightPos.z = your.z;
		vec_set(my.x,FrontRightPos);
		wait(1);
	}
}

action LeftMarkerAction()
{
	set(my, PASSABLE);
	my.red = 100;
	my.ambient = 100;
	my.lightrange = 200;
	while(1)
	{
		FrontLeftPos.x = your.x + (50 * cos(your.pan)) - (50 * sin(your.pan));
	    FrontLeftPos.y = your.y + (50 * sin(your.pan)) + (50 * cos(your.pan));
	    FrontLeftPos.z = your.z;
		vec_set(my.x,FrontLeftPos);
		wait(1);
	}
}

function CreateMarker()
{
	FrontRightPos.x = my.x + (50 * cos(my.pan)) + (50 * sin(my.pan));
	FrontRightPos.y = my.y + (50 * sin(my.pan)) - (50 * cos(my.pan));
	FrontRightPos.z = my.z;
	ent_create("box.mdl", FrontRightPos, RightMarkerAction);
	
	FrontLeftPos.x = my.x + (50 * cos(my.pan)) - (50 * sin(my.pan));
	FrontLeftPos.y = my.y + (50 * sin(my.pan)) + (50 * cos(my.pan));
	FrontLeftPos.z = my.z;
	ent_create("box.mdl", FrontLeftPos, LeftMarkerAction);
	wait(1);
}



Now I have two transparent boxes floating slightly in front of my entity, 1 to the left and 1 to the right. They visually represent the vector positions that will check whether my entity has bumped into a wall. I don't know how exactly to perform that check. The AUM used C-SCript and the check was done using
Code:
BooleanVar = content(VectorToBeChecked);
if(BooleanVar == content_solid) 
{ ObstcaleInThatDirection = 1;}


What's the lite-c equivalent of content() and content_solid?
Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/29/14 18:26

While waiting for a response, I found "in_solid", so I tried using it to detect whether my marker boxes were inside walls. When it didn't work, I copied and pasted the example from the manual and replaced my player's action code with it. I still don't get any response to show that it has detected a wall when my player touches one.
Code:
while(1)
	{
		 c_move(me,vector(time_step*10,0,0), nullvector,0);
 	  if (in_solid)		// Is Entity inside a block?
 	  {
 	    error("Solid!");
 	  }
    if (in_passable) // Is Entity inside a passable block?
 	  {
 	    error("Passable!");
 	  }
 	  if (on_passable) // Is Entity on a passable block?
 	  {
 	    error("On water!");
 	  }
		wait(1);
	}

Posted By: Superku

Re: How to confirm collision with level blocks? - 07/29/14 19:14

Stuff like (c_?)content and in_solid and the like sadly is outdated and does not work with the more or less modern meshes generated by the Map Compiler.

Just do a c_trace from the player position to those of the floating boxes and check its result values for collision.
Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/30/14 00:35

I've bypassed the floating boxes now and I'm performing a trace directly from my player to the vectors where the boxes would have been located.
Code:
while(1)
{
.........
FrontRightPos.x = my.x + (50 * cos(my.pan)) + (50 * sin(my.pan));
	                FrontRightPos.y = my.y + (50 * sin(my.pan)) - (50 * cos(my.pan));
	                FrontRightPos.z = my.z;
	
	                FrontLeftPos.x = my.x + (50 * cos(my.pan)) - (50 * sin(my.pan));
	                FrontLeftPos.y = my.y + (50 * sin(my.pan)) + (50 * cos(my.pan));
	                FrontLeftPos.z = my.z;

if(c_trace(me, FrontRightPos, IGNORE_ME | IGNORE_MODELS | IGNORE_SPRITES | IGNORE_CONTENT)>0)
	   	            RightWall = 1;

	   	            
	   	            if(c_trace(me, FrontLeftPos, IGNORE_ME | IGNORE_MODELS | IGNORE_SPRITES | IGNORE_CONTENT)>0)
	   	            LeftWall = 1;
	   	            
	   	            if(RightWall == 1 && LeftWall == 1)
	   	            {
	   	            	dash = 0; my.animation = 0; FrontWall = 1; WallRunning = 1;
	   	            	printf("Front Wall!"); 
	   	            }
	   	            else if(LeftWall == 1 && RightWall == 0)
	   	            {
	   	            	dash = 0; my.animation = 0; WallRunning = 1;
	                	printf("Left Wall!");             	
   	            	}
   	            	else if(RightWall == 1 && LeftWall == 0)
   	            	{
   	            		dash = 0; my.animation = 0; WallRunning = 1;
	                	printf("Right wall!"); 
   	            	}
.............
}


Both booleans "Leftwall" and "Rightwall" are set to 1 the moment I run the function that checks, regardless of how far away the player is from a wall. I tried using HIT_TARGET and got the same results.
Code:
c_trace(me, FrontRightPos, IGNORE_ME | IGNORE_MODELS | IGNORE_SPRITES | IGNORE_CONTENT);
	   	            if(HIT_TARGET)
	   	            {
	   	            	RightWall = 1;
   	            	}


These first two options ALWAYS respond as if a wall was detected, even if it wasn't. If I use hit.nx to check, I'll never get a positive response, wall or not.
Posted By: DLively

Re: How to confirm collision with level blocks? - 07/30/14 00:55

Try this:
Code:
result = c_trace(my.x, FrontRightPos.x, IGNORE_ME | IGNORE_MODELS | IGNORE_SPRITES | IGNORE_CONTENT);
	   	            if(result > 0)
	   	            {
	   	            	RightWall = 1;
   	            	}

Posted By: tolu619

Re: How to confirm collision with level blocks? - 07/30/14 01:19

Originally Posted By: DLively
Try this:
Code:
result = c_trace(my.x, FrontRightPos.x, IGNORE_ME | IGNORE_MODELS | IGNORE_SPRITES | IGNORE_CONTENT);
	   	            if(result > 0)
	   	            {
	   	            	RightWall = 1;
   	            	}


Didn't work. I've tried trace_hit, hit.texname (pretty much everything that follows the dot after 'hit'), I've been going through the manual and trying everything for 2 hours now. Everything I've tried either always gives a positive result or always gives a negative result, regardless of my actual position relative to a wall.
Posted By: tolu619

Re: How to confirm collision with level blocks? - 08/05/14 20:41

Hello? Guys, this issue is still unresolved!
Posted By: Superku

Re: How to confirm collision with level blocks? - 08/05/14 21:35

Debug it then.
Check the you-pointer, create CUBE_MDLs at hit positions, draw values and so on.
You have to do it yourself, apparently.

Suggestion:
RightWall = trace_hit; // no if-case, just like that after the c_trace
vec_set(vRightWallTarget,target);
... same for left

then draw_line3d from player to those target vectors
Posted By: sivan

Re: How to confirm collision with level blocks? - 08/06/14 06:26

what I mentioned code earlier features debugging by drawing lines of c-tracings as Superku mentioned. beside preventing to go deep into water.
Posted By: tolu619

Re: How to confirm collision with level blocks? - 08/06/14 09:02

Alright, thanks. I have exams coming up so I'm taking a break for about 6 weeks. I'll let you guys know how it goes when I get back to it. Here's a trailer for what I have so far http://t.co/uW1jRhnisN
© 2024 lite-C Forums