Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, Quad), 903 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
walking on terrain with 4 legs #411272
11/15/12 06:26
11/15/12 06:26
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline OP
User
JazzDude  Offline OP
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
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

Re: walking on terrain with 4 legs [Re: JazzDude] #411273
11/15/12 06:53
11/15/12 06:53
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
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.

Re: walking on terrain with 4 legs [Re: 3dgs_snake] #411274
11/15/12 07:10
11/15/12 07:10
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline OP
User
JazzDude  Offline OP
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
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);


Re: walking on terrain with 4 legs [Re: JazzDude] #411275
11/15/12 07:30
11/15/12 07:30
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
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


Visit my site: www.masterq32.de
Re: walking on terrain with 4 legs [Re: JazzDude] #411276
11/15/12 07:32
11/15/12 07:32
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
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;


Re: walking on terrain with 4 legs [Re: 3dgs_snake] #411293
11/15/12 11:09
11/15/12 11:09
Joined: Jan 2003
Posts: 4,305
Damocles Offline
Expert
Damocles  Offline
Expert

Joined: Jan 2003
Posts: 4,305
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.

Re: walking on terrain with 4 legs [Re: Damocles] #411309
11/15/12 13:48
11/15/12 13:48
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline OP
User
JazzDude  Offline OP
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
Thanks, guys. The fun begins. Pegasus wouldn't have this problem.

Re: walking on terrain with 4 legs [Re: JazzDude] #411959
11/21/12 15:03
11/21/12 15:03
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
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


Free world editor for 3D Gamestudio: MapBuilder Editor
Re: walking on terrain with 4 legs [Re: sivan] #412289
11/24/12 22:34
11/24/12 22:34
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline OP
User
JazzDude  Offline OP
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
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.

Last edited by JazzDude; 11/25/12 18:06.
Re: walking on terrain with 4 legs [Re: JazzDude] #412405
11/26/12 22:29
11/26/12 22:29
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline OP
User
JazzDude  Offline OP
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
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);
	}  
}


Page 1 of 2 1 2

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