weird c_trace behaviour...

Posted By: Superku

weird c_trace behaviour... - 11/15/10 13:27

I have an entity that is placed before a c_trace call and afterwards I move it somewhere else so it cannot be hit by the trace.
The problem is, c_trace does not know that the entity is there when I don't use a "wait(1);" after placing the obstacle.

Without wait:



With wait:



Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

void main() {
	video_mode = 11;
	fps_max = 60;
	level_load(NULL);
	camera.x = -100;
	player = ent_create(CUBE_MDL,nullvector,NULL);
	set(player,POLYGON);
	wait(1);
	c_setminmax(player);
	while(1) {
		player.y = 0;
		//wait(1); // <------------ !!
		c_trace(vector(0,0,32),vector(0,0,-32),IGNORE_PASSABLE);
		player.y = 32;
		
		draw_line3d(vector(0,0,32),NULL,100);
		if(trace_hit) {
			draw_line3d(vector(0,0,32),COLOR_RED,100);
			draw_line3d(vector(0,0,-32),COLOR_RED,100);
		}
		else {
			draw_line3d(vector(0,0,32),COLOR_GREEN,100);
			draw_line3d(vector(0,0,-32),COLOR_GREEN,100);
		}
		wait(1);
	}
}



What's wrong?
Thanks in advance!
Posted By: Michael_Schwarz

Re: weird c_trace behaviour... - 11/15/10 16:15

I don't see why that would be "weird behavior", seems more like working as intended.
Posted By: Superku

Re: weird c_trace behaviour... - 11/15/10 16:24

Because c_trace should take the current situation into account, shouldn't it? Otherwise, when I move several objects within only one function, the collision behaviour would be wrong (i.e. move a platform first so it is below the player, but as the "collision hull" would stay at the old position, the player's gravity-trace would not detect it and thus the player would fall into some pits below).
Posted By: Michael_Schwarz

Re: weird c_trace behaviour... - 11/15/10 16:26

as long as you don't move it at super high speeds, that wouldn't be the case
Posted By: Superku

Re: weird c_trace behaviour... - 11/15/10 16:38

Quote:
as long as you don't move it at super high speeds, that wouldn't be the case


No, there are several issues, not just that stupid example.
Take a platform that moves vertically up (or down). Because the collision hull is not updated immediately, the player's gravity-trace will take the old position into account and thus he will sink into that platform (one-frame-lag) or float above it, when the platform moves down (I know some workarounds, of course).

I'm currently writing a hitbox code where my player-shoot function c_traces for enemies. If some enemy is hit, the hitboxes are placed and a short range c_trace (which now ignores enemies) detects which box has been hit. That does not work without a wait, because of the aforesaid reason.
Posted By: bart_the_13th

Re: weird c_trace behaviour... - 11/16/10 03:28

Well, you can move the checking to be after/below the wait(1) statement.
Then use another variable to keep the c_trace result instead of using trace_hit
Posted By: JibbSmart

Re: weird c_trace behaviour... - 11/16/10 03:50

I guess there's a lot of internal stuff done during a wait. Perhaps a c_move would ensure it all got updated? The function should be efficient enough that with IGNORE_WORLD | IGNORE_MAPS | IGNORE_SPRITES it wouldn't be wasteful. It's just a matter of whether or not it works...

Jibb
Posted By: Superku

Re: weird c_trace behaviour... - 11/17/10 22:34

Quote:
Perhaps a c_move would ensure it all got updated?

Thanks Julz, you helped me out... again!
Posted By: JibbSmart

Re: weird c_trace behaviour... - 11/18/10 16:15

Oh, haha laugh That was lucky. It was just a guess. I'm glad it works!
© 2023 lite-C Forums