Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (henrybane), 1,499 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Smoother falling and walking up stairs? #424827
06/22/13 15:19
06/22/13 15:19
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline 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:

Code:
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

M
Malice
Unregistered
Malice
Unregistered
M



Try modifying this gravity block that I modified form a post by MasterQ32(Thank you MasterQ32!)

Code:
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 Offline OP
User
Ruben  Offline 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:

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

M
Malice
Unregistered
Malice
Unregistered
M



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: ] #424946
06/24/13 16:42
06/24/13 16:42
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
If you could search more for this, you could fine it on my website:
http://badcom.at.ua/load/3dgs_stuff/player_movement/3-1-0-11

Greets


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Smoother falling and walking up stairs? [Re: 3run] #424950
06/24/13 17:18
06/24/13 17:18

M
Malice
Unregistered
Malice
Unregistered
M



@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.

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