walking on terrain with 4 legs

Posted By: JazzDude

walking on terrain with 4 legs - 11/15/12 06:26

Maybe someone can give me an idea about this...
I have a four-legged animal that walks on the terrain just fine except it doesn't tilt to stay perpendicular to the surface.
Going up hill its back feet are off the ground. Downhill the front feet are off the ground.

Help! frown
Posted By: 3dgs_snake

Re: walking on terrain with 4 legs - 11/15/12 06:53

Hi,

Need to do a trace for front leg and back leg, and use that with the distance between the traces to calculate the tilt angle.
Posted By: JazzDude

Re: walking on terrain with 4 legs - 11/15/12 07:10

Ooooh, that sounds too tricky for my klutzy koding non-skill.
Here's what I have so far. It works going up hill and on the level, but not downhill.

Code:
ent_terrain = you;
	burro = me;
	vec_set(temp, you.x);
	vec_sub(temp,my.x);
        my.tilt = vec_to_angle(you.tilt,temp);

Posted By: MasterQ32

Re: walking on terrain with 4 legs - 11/15/12 07:30

sorry, but i have to say: this is bullshit grin

you can try something like this:

Code:
VECTOR front;
VECTOR back;
// Calculate front position
vec_set(front, vector(10, 0, 0)); // Distance 10 from model center
vec_rotate(front, vector(my.pan, 0, 0));
vec_add(front, my.x);
front.z += 100;

// Calculate back position
vec_set(back, vector(-10, 0, 0)); // Distance 10 from model center
vec_rotate(back, vector(my.pan, 0, 0));
vec_add(back, my.x);
back.z += 100;

var h1 = c_trace(back, vector(back.x, back.y, back.z - 200), IGNORE_ME | IGNORE_PASSABLE | ...);
var h2 = c_trace(front, vector(front.x, front.y, front.z - 200), IGNORE_ME | IGNORE_PASSABLE | ...);

var dist = h2 - h1;
my.tilt = atanv(dist / 20); // 20 is the distance between the front and the back vector before rotating and so



here i am calculating the height at the front and at the back of a model
the difference between both parts is the slope height
with arcus tangens you can convert the slope height into an angle you can use laugh

btw, code is not tested, also you have to correct the c_trace mode argument (i'm just simplified it.

greetz
Felix
Posted By: 3dgs_snake

Re: walking on terrain with 4 legs - 11/15/12 07:32

I'm not a C-Script programer so, basically, this is what you need to do in Lite-C laugh :

Code:
// Calculate rotation
VECTOR *front = vector(32, 0, 0);   // Fron location
// Rotate front relative to the entity
vec_rotate(front, vector(my.pan, 0, 0)); // Take into account only pan angle
		
VECTOR trace_pos;   // The trace position
		
// Do a first trace for  the front legs
vec_set(trace_pos, my.x);
vec_add(trace_pos, front);
var front_trace = c_trace (trace_pos, vector(trace_pos.x, trace_pos.y, trace_pos.z - 10000), IGNORE_ME | IGNORE_PASSABLE);
				
		
// Do a second trace for the rear legs
VECTOR *rear = vector(0, 0, 0);
vec_set(rear, front);

// reverse x direction
rear.x *= -1;
vec_set(trace_pos, my.x);
vec_add(trace_pos, rear);
var rear_trace = c_trace (trace_pos, vector(trace_pos.x, trace_pos.y, trace_pos.z - 10000), IGNORE_ME | IGNORE_PASSABLE);
		
// Calculate the tilt based on the traces pos
var delta = front_trace - rear_trace;
var dist = 64; // 64 (size of the animal)
var tilt_angle = -atan2v(delta, dist);
my.tilt = tilt_angle;

Posted By: Damocles

Re: walking on terrain with 4 legs - 11/15/12 11:09

instead of tilting the model, it might be better to
use an appropriate animation for downhill and uphill movement.

(Though You could tilt it a bit to make the legs touch the ground too.)

Else the movement would look kind of fake, like a stiff platic toy.
Posted By: JazzDude

Re: walking on terrain with 4 legs - 11/15/12 13:48

Thanks, guys. The fun begins. Pegasus wouldn't have this problem.
Posted By: sivan

Re: walking on terrain with 4 legs - 11/21/12 15:03

I agree with Damocles, in case of humans it is also disturbing if zoomed close, so better to suck with creating animation than with bad final result... or use only vehicles beside pegazus grin
Posted By: JazzDude

Re: walking on terrain with 4 legs - 11/24/12 22:34

I'm ready to try the animation approach since I haven't been able to do it the other way. So, how would I code this:

If (my.z is increasing)

Comparing my present z with a previous z dynamically



I'm stuck,thanks.
Posted By: JazzDude

Re: walking on terrain with 4 legs - 11/26/12 22:29

This solved the problem. I still need to smooth the rotation.

Code:
action follow_player
{ 
	while(player == 0){wait(1);} 
	c_setminmax(me);
	temp.z -= 10000;
	my.z -=c_trace(my.pos,temp,use_polygon|ignore_me|ignore_passable|ignore_passents)-9;
	my.health = 100;//I've got 100 Healthpoints 
	my.shadow = on;
	my.cast = on;
	mat_shadow.alpha = 60;
	while (my.health > 0)//as long as I live 
	{
		if (vec_dist (my.x, player.x) < 500 && player.health > 0)		
			{   
				vec_set(temp, player.x);    
				vec_sub(temp, my.x);   
				vec_to_angle(my.pan, temp);   
				vec_set (temp, my.x);   
			}  
		if (vec_dist (my.x, player.x) > 60)//&&(mouse_right == 1)  
			{   
				vec_set(temp, player.x);    
				vec_sub(temp, my.x);   
				vec_to_angle(my.pan, temp); 
				temp.z -= 10000;
				my.z -=c_trace(my.pos,temp,use_polygon|ignore_me|ignore_passable|ignore_passents)-9;
				walk_percent = (walk_percent +12*time_step*player_speed_land_walk)%100;
				ent_animate(me,"walk",walk_percent,anm_cycle);
				c_move(me,vector(2*time_step,0,0),vector(0,0,my.PlayerGravity),glide|ignore_me|ignore_passable|ignore_passents); 
			}  
		if (vec_dist (my.x, player.x) < 500)&&(mouse_right != 1) 
			{
			temp.z -= 10000;
			my.z -=c_trace(my.pos,temp,use_polygon|ignore_me|ignore_passable|ignore_passents)-9;
			stand_percent = (stand_percent +0.05*time_step)%100;
			ent_animate(me,"stand",stand_percent,anm_cycle);
			}
	wait(1);
	}  
}

Posted By: EpsiloN

Re: walking on terrain with 4 legs - 12/09/12 18:31

Cant you use the normal vector returned by a single c_trace ? Not tracing twice or animating for every possible tilt angle... laugh

I'm not shure , but it should work with models , not only level blocks...
This is from the manual :
Code:
function test
{	
  vec_set(temp, my.x);
 	temp.z -= 1000; // 1000 Quants down
 	c_trace(my.x, temp, IGNORE_ME); 
 	vec_set(my.x, target);
 	vec_to_angle(my.pan, normal); // put on surface
}

© 2024 lite-C Forums