|
in need of help for my movement code
#254259
03/02/09 06:19
03/02/09 06:19
|
Joined: Jun 2007
Posts: 152 Norway
Darkyyes
OP
Member
|
OP
Member
Joined: Jun 2007
Posts: 152
Norway
|
ok first this code works perfectly on flat ground or downwar hills, but when I try to walk/run up slopes it sometimes get stuck for a while, keep holding my left mouse button and keep running my character finally gets up the slope, I've tried making him be higher in the air but it doesnt help. I dont know what to do.
#define gravity_constant -2
// z_smooth controls how smooth the z-adjustment movement is.
// Values are 0 through 1, where 0 is more smooth and 1 is not smooth at all
#define z_smooth .0
// Height to float the entity bounding box off the ground
#define my_z_offset 5
action player()
{
player = my; // I'm the player
c_setminmax(me);
VECTOR move_to_vector;
var trace_to_ground;
var distance_to_ground; // the distance between player's origin and the ground
var z_adjust = 0;
var distance_moved;
my.albedo=0;
VECTOR temp[3];VECTOR temp2[3];VECTOR temp_target[3];VECTOR pos1[3];VECTOR pos2[3];
var anim_percentage;
var rot_speed = 6; /////new var
var new_angle;///////new var
vec_set(temp_target,my.x);
while(1)
{
trace_to_ground = c_trace(my.x, vector(my.x,my.y,my.z-80000), IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX);
distance_to_ground = trace_to_ground - my_z_offset;
distance_moved = c_move(me, vector(0,0,move_to_vector.z + (z_adjust * z_smooth)), nullvector, GLIDE|IGNORE_SPRITES|IGNORE_PASSABLE|USE_BOX);
if ((distance_to_ground > 0) && (distance_to_ground < 3) && (move_to_vector.z < 0))
{
z_adjust = (trace_to_ground * -1) + my_z_offset;
move_to_vector.z = 0;
}
else
{
// If the acceleration of gravity would cause the entity to be moved below the ground, shorten
// the fall so that the entity is put directly on to the ground.
accelerate(move_to_vector.z, (gravity_constant * time_step), 0);
if (move_to_vector.z < (distance_to_ground * -1))
{
// move_to_vector.z = (distance_to_ground * -1) * .3;
z_adjust = (trace_to_ground * -1) + my_z_offset;
move_to_vector.z = 0;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
if(mouse_left == 1 && key_shiftl == 0)
{
pos1.x = mouse_pos.x;pos1.y = mouse_pos.y;pos1.z = 0;
vec_for_screen (pos1, camera);
pos2.x = mouse_pos.x;pos2.y = mouse_pos.y;pos2.z = 300000;
vec_for_screen (pos2, camera);
c_trace (pos1,pos2,IGNORE_ME|IGNORE_PASSABLE); //|IGNORE_MODELS
vec_set(temp_target,target);
if(vec_dist(my.x,temp_target.x)>90)
{
//vec_set(temp.x,temp_target.x);
//vec_sub(temp.x,my.x) ;
//vec_to_angle(my.pan,temp);
//my.pan = smooth(my.pan, 0.95);
////////////////////////////////////////////////new code//////////////////////////////////////////
vec_set(temp.x,temp_target.x);
vec_sub(temp.x, my.x);
vec_to_angle(new_angle, temp.x);
if (ang(new_angle - my.pan) < -8)
{
my.pan -= rot_speed * time_step;
}
else
{
if (abs(ang(new_angle - my.pan)) > 8)
{
my.pan += rot_speed * time_step;
}
}
my.tilt=0;
c_move (my, vector(12*time_step,0 , 0), nullvector, IGNORE_PASSABLE | GLIDE);
ent_animate(my, "run", anim_percentage, ANM_CYCLE);
anim_percentage += 10 * time_step;
}
if(vec_dist(my.x,temp_target.x)<90)
{
ent_animate(my, "stand", anim_percentage, ANM_CYCLE);
anim_percentage += 2 * time_step;
}
}
else
{
ent_animate(my, "stand", anim_percentage, ANM_CYCLE);
anim_percentage += 2 * time_step;
}
camera.x = player.x - 210 * cos(player.pan);
camera.y = player.y - 210 * sin(player.pan); // use the same value (250) here
camera.z = player.z + 130; // place the camera above the player, play with this value
camera.arc = 75;
camera.tilt = -10; // look down at the player
camera.pan = player.pan;
wait (1);
}
}
New to lite-c and gamestudio in general, thank you for reading. Com, A7 v7.7
|
|
|
Re: in need of help for my movement code
[Re: Darkyyes]
#254924
03/06/09 13:13
03/06/09 13:13
|
Joined: Jun 2007
Posts: 152 Norway
Darkyyes
OP
Member
|
OP
Member
Joined: Jun 2007
Posts: 152
Norway
|
no-one that can give me a code snippet on how to solve this?
New to lite-c and gamestudio in general, thank you for reading. Com, A7 v7.7
|
|
|
Re: in need of help for my movement code
[Re: MrGuest]
#255035
03/07/09 07:13
03/07/09 07:13
|
Joined: Jun 2007
Posts: 152 Norway
Darkyyes
OP
Member
|
OP
Member
Joined: Jun 2007
Posts: 152
Norway
|
hm, ok thanks, but I got a small thought saying that the collisions then is only on the small box am i right?
New to lite-c and gamestudio in general, thank you for reading. Com, A7 v7.7
|
|
|
|