Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (bdgogo), 1,447 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19056 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Setting a tank's tilt to the slope it is on: #237026
11/17/08 18:00
11/17/08 18:00
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline OP
Member
heinekenbottle  Offline OP
Member

Joined: Oct 2008
Posts: 218
Nashua NH
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;
Re: Setting a tank's tilt to the slope it is on: [Re: heinekenbottle] #237475
11/20/08 09:43
11/20/08 09:43
Joined: Jul 2007
Posts: 53
Germany
Henning Offline
Junior Member
Henning  Offline
Junior Member

Joined: Jul 2007
Posts: 53
Germany
Hello heinekenbottle,

when I suppose, that your tank is designed with the x-axis pointing forward, then the result is clear. The normal vector is pointing away from the scanned surface, meaning upwards with a slight deviation depending on terrain slope. Vec-to-angle copies this direction to the pan and tilt angles of your tank, so it is pointing upwards, too. Instead you should try to apply the (90-tilt) angle of the normal vector to the tilt and roll angle of your tank depending on direction of the terrain slope which you can find in the pan angle of the normal vector. It should point to downward direction of slope.

Sorry, it is that complex.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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

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

Powered by UBB.threads™ PHP Forum Software 7.7.1