2 registered members (dr_panther, Quad),
903
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
OP
User
|
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!
|
|
|
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
OP
User
|
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.
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
Expert
|
Expert
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
|
sorry, but i have to say: this is bullshit you can try something like this:
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 btw, code is not tested, also you have to correct the c_trace mode argument (i'm just simplified it. greetz Felix
|
|
|
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
Senior Member
|
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 :
// 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: sivan]
#412289
11/24/12 22:34
11/24/12 22:34
|
Joined: Sep 2003
Posts: 733 Whitefish, Montana
JazzDude
OP
User
|
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
OP
User
|
OP
User
Joined: Sep 2003
Posts: 733
Whitefish, Montana
|
This solved the problem. I still need to smooth the rotation.
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);
}
}
|
|
|
|