I've been trying to get my tank to tilt properly when it is on a sloped block. The first time I did it, I tried using a combination of C-Trace() and trig.

Then I read in the manual about "normal" and seeing my folly of doing it the hard way with trig, I tried using vec_to_angle with normal after doing a c_trace.

In both cases, on flat ground, the tank was stuck at a 90 degree tilt. Here is the code: after the double slash is the line trying to use normal (I used pan because the example in the manual used pan, I got the same error using tilt.) In between the /* comment is the trigonometry attempt.

Code:
action pTank()
{
	wait(1);
	c_setminmax(me);
	set(my,FLAG2 | SHADOW | CAST | METAL);
	player = my;
	my.health = 100;
	turret = ent_create("tankturret.mdl",my.x,pTurret);
	var bottom;
	vec_for_min(bottom,me);
	while(my.health > 0)
	{
		my.pan += 10 * (key_a - key_d) * time_step;
		speed.x = velocity * (key_w - key_s) * time_step;
		speed.y = 0;
		c_trace(my.x,vector(my.x,my.y,-2000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX);
		[color:#33FF33]//vec_to_angle(my.pan,normal);[/color]
		var distDown = my.z + bottom - target.z;
		if(distDown > 0)
			grav.z = -20 * time_step;
		else
			grav.z = 0;[color:#FF0000]/*
		var opp = abs(my.max_x - my.min_x);
		var adj1 = c_trace(vector(my.max_x,my.y,bottom),vector(my.max_x,my.y,-2000), IGNORE_ME | IGNORE_PASSABLE);
		var adj2 = c_trace(vector(my.min_x,my.y,bottom),vector(my.min_x,my.y,-2000), IGNORE_ME | IGNORE_PASSABLE);
		if(adj1 > 0)
			my.tilt = -atan(adj1/opp);
		else
			my.tilt = 0;
		if(adj2 > 0)
			my.tilt = atan(adj2/opp);
		else
			my.tilt = 0;*/[/color]
		c_move(my,speed,grav,IGNORE_FLAG2 | IGNORE_PASSABLE | GLIDE);
		camera.pan = player.pan;
		camera.tilt = -85;
		camera.x = my.x;
		camera.y = my.y;
		camera.z += (0.5 * mickey.z * ((camera.z > 1500) && (camera.z < 4000)));
			if(camera.z < 1500) camera.z = 1501;
			if(camera.z > 4000) camera.z = 3999;
		wait(1);
	}
}


EDIT: Used color to make the problem area stand out

Last edited by heinekenbottle; 11/17/08 18:05.

I was once Anonymous_Alcoholic.

Code Breakpoint;