1 registered members (henrybane),
1,499
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Smoother falling and walking up stairs?
#424827
06/22/13 15:19
06/22/13 15:19
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
It seems that my player is capable of walking up and down stairs just fine, which is great. My player can also step off a ledge, and end up on the ground. The only problem is that my player does not have a smooth animation transition when doing these actions. When he walks up or down stairs, he warps up and down instantly, instead of showing a smooth up and down movement of the player moving up and down with each step as he climbs. Also, when my player steps off a ledge, instead of showing a smooth falling animation, he just instantly warps to the bottom, with no movement animation between falling off the ledge and landing on the ground. Does anyone know of a way to add a smooth transitional movement for up and/or down movement? Here is some of my code for my player in making him move about:
action walking_guard()
{
...
set(my, POLYGON);
VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance from
// player origin to lowest
// vertex
my.STATE = 1;
while (1)
{
...
// state 1: walking /////////////////
if (my.STATE == 1)
{
// rotate the entity with the arrow keys
my.pan += (key_cul-key_cur)*11*time_step;
// move the entity forward/backward with the
// arrow keys
distance = (key_cuu-key_cud)*20*time_step;
move_friction = 0.5;
c_move(me, vector(distance,0,0), NULL, GLIDE);
if((key_cuu == 1) || (key_cud == 1))
{
// animate the entity
my.ANIMATION += 1*distance;
ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
}
else
{
my.ANIMATION += 1*time_step;
ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE);
// "idle" stance continual animation
}
// adjust entity to the ground height, using a
// downwards trace
c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
my.z = hit.z - vFeet.z; // always place player's
// feet on the ground
...
}
Last edited by Ruben; 06/22/13 15:21.
|
|
|
Re: Smoother falling and walking up stairs?
[Re: Ruben]
#424830
06/22/13 15:47
06/22/13 15:47
|
Malice
Unregistered
|
Malice
Unregistered
|
Try modifying this gravity block that I modified form a post by MasterQ32(Thank you MasterQ32!)
my.JUMP_FORCE = 16;
gravity_var = 0;
gravity_force = 3;
jumplck = 0;
shift_lck = 0;
my.FEET_HEIGHT = -my.min_z+1;
while(x)
{
// your code here
if( (key_shift) && !shift_lck && !jumplck)
{
gravity_var = my.JUMP_FORCE;
jumplck = 1;
}
shift_lck = key_shift;
gravity_var -= gravity_force * time_step;
c_move ( my , YOUR_MOVE_VEC , vector (0 , 0 , gravity_var *time_step), IGNORE_PASSABLE | GLIDE ); if(c_trace(my.x, vector(my.x, my.y, my.z - my.FEET_HEIGHT), IGNORE_ME | IGNORE_PASSABLE | IGNORE_PASSENTS | USE_POLYGON))
{
my.z = target.z + (my.FEET_HEIGHT);
gravity_var = 0;
jumplck = 0;
}
wait(1);
}
The problem is that you are setting to player to the z result of a trace.
Last edited by Malice; 06/22/13 15:49.
|
|
|
Re: Smoother falling and walking up stairs?
[Re: ]
#424944
06/24/13 15:59
06/24/13 15:59
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Thank you Malice. I tailored your code for my program, and it seems that my player character now has a smooth falling animation when falling over an edge. Thank you. However, when my player character walks up stairs, it still shows an up and down jittery effect; but when the same player walks down stairs, the player moves smoothly downstairs. Do you know how to eliminate that problem? Here is how I tailored your code into my code:
action walking_guard()
{
my.JUMP_FORCE = 16;
var gravity_var = 0;
var gravity_force = 3;
var jumplck = 0;
var shift_lck = 0;
my.FEET_HEIGHT = -my.min_z+1;
my.eflags |= FAT | NARROW; // set both flags to prevent automatic
// recalculation on scale changes.
my.emask |= ENABLE_SHOOT;
my.event = spell_fly_damage;
vec_set(my.min_x,vector(-15,-15,-10)); // set bounding box to individual
// values
vec_set(my.max_x,vector(15,15,45));
my.HEALTH = 500;
camera_follow(me);
// set FLAG2 to make the guard detectable by c_scan,
// and store the guard pointer in its own CREATOR skill
// so that the detecting entity knows its enemy
set(my,FLAG2);
my.CREATOR = me;
set(my, POLYGON);
my.STATE = 1;
while(my.x)
{
player_health();
if( (key_shift) && !shift_lck && !jumplck)
{
gravity_var = my.JUMP_FORCE;
jumplck = 1;
}
shift_lck = key_shift;
gravity_var -= gravity_force * time_step;
if (my.STATE == 1)
{
my.pan += (key_cul-key_cur)*11*time_step;
// move the entity forward/backward with the arrow keys
distance = (key_cuu-key_cud)*20*time_step;
c_move ( me, vector(distance,0,0), vector(0,0,gravity_var *
time_step), IGNORE_PASSABLE | GLIDE );
if((key_cuu == 1) || (key_cud == 1))
{
// animate the entity
my.ANIMATION += 1*distance;
ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
}
else
{
my.ANIMATION += 1*time_step;
ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE); // "idle" stance
// continual animation
}
// adjust entity to the ground height, using a downwards trace
if(c_trace(my.x, vector(my.x, my.y, my.z - my.FEET_HEIGHT), IGNORE_ME
| IGNORE_PASSABLE | IGNORE_PASSENTS | USE_POLYGON))
{
my.z = target.z + (my.FEET_HEIGHT);
gravity_var = 0;
jumplck = 0;
}
...
}
|
|
|
Re: Smoother falling and walking up stairs?
[Re: Ruben]
#424945
06/24/13 16:18
06/24/13 16:18
|
Malice
Unregistered
|
Malice
Unregistered
|
I will tell you that there are code solutions but I just tend to place a invisible ramp right over the steps. I have use many methods to make this work, but the fact is users of your game will prefer a smooth climbing movement to a bumpy camera bouncing one. But if you us a level solution like the invisible ramp then you might had to write a action for the 'ramp' that sets the players gravity lower when on the ramp to reduce sliding. There are many ways to deal with this. Another option is having a standard step height/depth and then you can move the player to a vector for the step while having gravity turned off. Or use two invisible ents at top and bottom and when the player starts up down steps you can make changes you need to get the effect you want. By giving the entities matching id skills and then testing for which step_ent is in the move direction then you can further customize the behavior of the player on steps.
EDIT* The jumping-up movement happens when suddenly your gravity c_trace hits the next step up and you pop up to that z level. You need to know the player is on steps and which way he is moving and then you can use logic to change the behavior of his movement.
EDIT* I am glad I helped but please give the code credit to MasterQ32 I didn't come up with this compact movement code.
Last edited by Malice; 06/24/13 16:26.
|
|
|
Re: Smoother falling and walking up stairs?
[Re: 3run]
#424950
06/24/13 17:18
06/24/13 17:18
|
Malice
Unregistered
|
Malice
Unregistered
|
@3Run Thank you for another great code set. So clean and compact, awesome! Now I feel a little stupid as I was in the middle of making a horrible diagram and writing a description and code set for my level solution. Thank you again 3Run !
@Ruban if you are not doing it already. Then you should grabs these code snips and code sets people post for you and save them in a library folder. Even stuff that doesn't solve your current problem comes in handy later. It's always easier to search through you library of snip( by file title or a index file) first instead of trying to search the AUM or Forum. Just advice if you are already doing this I am sorry then for saying it.
Last edited by Malice; 06/24/13 17:26.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|