Hey guys...

Can anyone please, help me out here, by telling why does this happen?


I'm really frustrated right now.. Spent few days working on movement code, and at the end it turns out to be like on the screen above.. Before showing my code, a little 'intro'. I used two separate models, one handles gravity and everything related to Z movement, the other one is responsible for XY movement. Also used gravity script from Superku's Tip of the Week series (it looks like the bbox size needs to be box shaped, other ways I faced some strange behaviours, can post demo if needed as well). Also, I do and I can understand, that cause of the ellipsoid shape, bbox can a bit penetrate the wall (on the both upper and lower ends of the bbox), but not like this, right? Player can simply go though the whole wall to the other side.

Here is the code:
Code:
#include <acknex.h>
#include <default.c>
#include <windows.h>
#include <strio.c>

#define PRAGMA_PATH "data"

#define PRAGMA_POINTER

#define TRACE_FLAGS (IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_MAPS | IGNORE_SPRITES | IGNORE_CONTENT)
#define MOVE_FLAGS (IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | IGNORE_MAPS | IGNORE_SPRITES | IGNORE_CONTENT)

ENTITY *hero_ent;
ENTITY *hero_xy_ent;

void level_setup_world(){
	
	sun_light = 0;
	sun_angle.pan = 270;
	sun_angle.tilt = -25;
	
	vec_set(&d3d_lodfactor, vector(12.5, 25, 50));
	
	camera->clip_near = 1;
	camera->clip_far = 45000;
	camera->fog_start = 1;
	camera->fog_end = 40000;
	
	fog_color = 4;
	vec_set(&d3d_fogcolor4.blue, vector(128, 128, 128));
	vec_set(&sky_color.blue, &d3d_fogcolor4.blue);
	
}

void player_xy_collider(){
	
	proc_mode = PROC_LATE;
	
	VECTOR input, abs_dist;
	vec_fill(&input, 0);
	vec_fill(&abs_dist, 0);
	var movement_speed = 8.5, movement_friction = 0.85;
	
	hero_xy_ent = my;
	set(my, TRANSLUCENT);
	c_setminmax(my);
	
	while(!hero_ent){ wait(1); }
	
	while(my){
		
		input.x = movement_speed * (key_w - key_s);
		input.y = movement_speed * (key_a - key_d);
		input.z = 0;
		
		if(vec_length(vector(input.x, input.y, 0)) > movement_speed){
			var len = sqrt(input.x * input.x + input.y * input.y);
			input.x *= ((movement_speed) / len);
			input.y *= ((movement_speed) / len);
		}
		
		vec_rotate(&input, vector(camera->pan, 0, 0));		
		accelerate(&abs_dist.x, input.x * time_step, movement_friction);
		accelerate(&abs_dist.y, input.y * time_step, movement_friction);
		c_move(my, nullvector, vector(abs_dist.x, abs_dist.y, 0), MOVE_FLAGS | IGNORE_MODELS | GLIDE);
		
		if(hero_ent){
			hero_ent->x = my->x;
			hero_ent->y = my->y;
			my->z = hero_ent->z + 16;
		}
		
		camera->pan = cycle(camera->pan - mickey.x / 6.5, 0, 360);
		camera->tilt = clamp(camera->tilt - mickey.y / 6.5, -90, 90);		
		camera->x = my->x + fcos((camera->pan), fcos(camera->tilt, -128));
		camera->y = my->y + fsin((camera->pan), fcos(camera->tilt, -128));
		camera->z = my->z + fsin(camera->tilt, -128);		
		camera->arc = 90;
		
		wait(1);
	}
}

action player_controller(){
	
	VECTOR force;
	vec_fill(&force, 0);
	var foot_height = 0, soil_height = 0, soil_contact = 0;
	var jump_height = 16, jump_key_off = 0;
	
	hero_ent = my;
	set(my, INVISIBLE);
	
	my->scale_z = 0.5;
	wait(1);
	c_setminmax(my);	

	VECTOR temp;
	vec_for_min(&temp, my);
	foot_height = (temp.z * my->scale_z) - 0;

	ent_create("bbox_npc.mdl", &my->x, player_xy_collider);

	while(my){
		
		if(force.z <= 0){
			vec_set(&temp, vector(my->x, my->y, my->z - 150 + foot_height));
			c_trace(&my->x, &temp, TRACE_FLAGS | IGNORE_MODELS | USE_BOX);
			soil_height = temp.z - foot_height;
			if(trace_hit){ soil_height = target.z - foot_height; }
		}
		
		if(my->z > soil_height + (5 + 20 * soil_contact) * time_step || force.z > 0){
			soil_contact = 0;
			force.z = maxv(force.z - 4 * time_step, -90);
		}
		else{
			c_move(me, nullvector, vector(0, 0, soil_height - my->z), MOVE_FLAGS | IGNORE_MODELS);
			soil_contact = 1;
			force.z = 0;
			
			if(key_space){
				if(jump_key_off == 0){
					jump_key_off = 1;
					force.z = jump_height;
				}
			}
			else{ jump_key_off = 0; }
		}
		
		if(force.z){
			c_move(me, nullvector, vector(0, 0, maxv(force.z * time_step, soil_height - my->z)), MOVE_FLAGS | IGNORE_MODELS);
			if(HIT_TARGET && normal.z < -0.5){ force.z = minv(force.z, 0); }
		}
		
		wait(1);
	}
}

void main(){
	
	video_set(800, 600, 16, 2);

	doppler_factor = 0;

	warn_level = 6;

	fps_max = 60;
	fps_min = 30;
	time_smooth = 0.9;

	freeze_mode = 1;
	level_load("def_map.wmb");
	wait(3);
	freeze_mode = 0;
	
	random_seed(0);

	level_setup_world();	
}

Just in order to show you that bboxes are set correct, here is a screen with both of them visible (in the first screen above only of the bbox, which is responsible for XY movement is visible):



And for those who are willing even test this (I want to say big thank you in advance to those risky folks), here is a demo (in order to 'walk in', walk towards the wall and jump few times):
Download link (19kb)

Originally I used smaller model sizes (like 32 was the total height of the character), thought maybe it was a bad size, increased it by 2 times, yet same results... I do really hope that some of you guys could help me out here, with an advice or by sharing your experience about the topic. Thank you all in advance.


Best regards.


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung