Any clear working example ?

Posted By: Realspawn

Any clear working example ? - 04/12/15 20:04

Is there any working clear example of :

A character moving using its animation (No bones) and have physics ?
i am trying but so far no luck laugh I looked in the forum but the topics i found have dead links or no answer at all laugh

thank you
Posted By: rayp

Re: Any clear working example ? - 04/12/15 23:13

Hello Dude.

Maybe this helps ? As always, just wrote it but didnt test yet ... guess i will, this time, need something similiar. So Feedback would be nice. I only used PhysicX one time, so if it wont work ... well lets see.

Code:
/*
   -------------------------------------------------------
   ---=[ phXhero.c ]=-------------------------------------
   -------------------------------------------------------
   lite-C A8 example of "hero / player - controller" using
    "PhysX engine" featuring vertex / frame / bone based
     animations + simple "die and blend out" - script
   note: all cam stuff is optional of course
   -------------------------------------------------------
   free contribution quick written by rayp 04.2015 germany
   -------------------------------------------------------
*/
#define animation_frame skill10             // animation percentage 0 - 100
#define health          skill11             // health points
#define speed           skill12             // ent's - speed factor * time_step = movement speed ( see mov_dist )

ENTITY* myplayer;                           // ent pointer holding "hero aka player"
VECTOR  mov_dist;                           // player is moved via this vector mov_dist.x / mov_dist.y ( use WASD )
STRING* str_walk = "walk";                  // framenames of animation ( open MED 2see them 4ex, guess u know :D )
var cam_mode     =      0;                  // 0 = player visible, 1 = invisible ( FPS-mode 4ex ).

void _mostbasicFPScam(){
   proc_mode = PROC_LATE;                   // maybe not. pls try.
   my.pan   += (mickey.x * 0.5) * time_step;// if cam-movment sucks swap X and Y of mickey for pan and tilt vectors!
   my.tilt  += (mickey.y * 0.5) * time_step;// ...as said above ... uneed2 test it
   vec_set     (camera.pan, my.pan);
   vec_set     (camera.x,   my.x);
   if ( cam_mode && !is (my, INVISIBLE)) set   (my, INVISIBLE);
   if (!cam_mode &&  is (my, INVISIBLE)) reset (my, INVISIBLE);
}

action playerWED(){	
   my.health = 100;                         // player starts with 100 health points
   my.speed  =   2;                         // movement speed
   pXent_settype (me, PH_CHAR, PH_CAPSULE); // register ent as physic object ... used it only one time, maybe change to PH_BOX?
// change bbox here if u want ( be4 the while! ) or something like:
// c_setminmax   (me);
// set           (my, POLYGON);             // or use vec_set min / max stuff see manual
// wait          (1);                       // use if u changed bbox be4
   myplayer  = me;                          // pointer to our hero ( u can use "player" instead )
 //my.frame  = Startframe of walking-anm;   // if using frame - anm
   while (my){
   // --------------------------------------------------------------------------------------------------------		
   // ---=[ physic - movement - part ]=-----------------------------------------------------------------------	
   // --------------------------------------------------------------------------------------------------------
      mov_dist.x = (my.speed * (key_w - key_s)) * time_step;     // prepare players X movement- ( WASD ) vector...
      mov_dist.y = (my.speed * (key_a - key_d)) * time_step;     // ...same4 Y of course!
    //mov_dist.z <- guess we dont need2 use ... only used physics one time, as i wrote already above
      pXent_movechar (me, mov_dist, NULL, 0);                    // finally move the player entity with our mov_dist - vector!
   // --------------------------------------------------------------------------------------------------------
   // ---=[ animation part ( vertex and bone ) ]=-------------------------------------------------------------
   // --------------------------------------------------------------------------------------------------------
      my.animation_frame += time_step * my.speed;	         // animate time corrected in (my.)speed
      my.animation_frame %= 100;                                 // 0 - 100 ( if anm "flickers" try without this line )
      ent_animate (me, str_walk, my.animation_frame, ANM_CYCLE); // finally ... cycle - animate me
   // ---=[ oldschool frame animation ... animates smooth from frame 20 to 30 ]=------------------------------
      /*
      my.frame += time_step * my.speed;
      if (my.frame >  30) my.next_frame = 20;                    // interpolate2 start frame...
      else                my.next_frame =  0;  		         // ...interpolate again
      if (my.frame >= 31) my.frame     -= 10;  	                 // 30 - 10 = 20 :D
   */
      if (my.health <= 0) break;                                 // no health? die!
      _mostbasicFPScam();                                        // xtreme simple cam-handle function ( cam_mode = 1 means player is INVISIBLE )
      wait (1);
   }
   // new school anm style again
   my.animation_frame = 0;                                       // using frames? then take my.frame = Start frame;
   while (my.animation_frame < 100){
      my.animation_frame += time_step * 4;
      ent_animate (me, "die", my.animation_frame, NULL);
      wait (1);   
   }
   // end of new school anm die part...if you wanna use oldschool stuff:
   // copy n paste vertex - frame - stuff from above, delete my.animation_frame=0+the while, adjust frame numbers = done!
   set (my, TRANSLUCENT | PASSABLE); 
   my.alpha = 100; while (my.alpha > 0) { my.alpha -= time_step; wait (1); } // TRANSLUCENT and while = optional of course
   wait       (1);
   ptr_remove (me);
}



If it works, ill add this code to lite-c - contributions asap.
GreetsNPeace!
Posted By: Realspawn

Re: Any clear working example ? - 04/12/15 23:48

i will give this a try laugh and let you know how it turns out.
It works laugh although the character somehow floats above the ground
so that's an issue ::)

Great work this is really usefull laugh

Posted By: rayp

Re: Any clear working example ? - 04/13/15 00:21

Quote:
floats above the ground
You setup players BBOX correct be4?
If the level is a model, instead of "blocks", you set its
Code:
POLYGON

flag, yes?

Your welcome man.
Ill post it in2 contributions then btw.
Works? Cool! ...got a "scripting - run" last days grin
Posted By: Realspawn

Re: Any clear working example ? - 04/13/15 00:35

I Pmmed you laugh

This stuff is excellent material laugh and deserves a place in the contribution section laugh
Posted By: 3run

Re: Any clear working example ? - 04/13/15 08:35

Originally Posted By: Realspawn
although the character somehow floats above the ground so that's an issue ::)
cct (PH_CHAR) will float above the ground anyway, there is only XY movement in the example tongue it needs gravity code.

Greets
Posted By: rayp

Re: Any clear working example ? - 04/13/15 09:13

Quote:
it needs gravity code.
feel free todo ^^
Posted By: 3run

Re: Any clear working example ? - 04/13/15 09:21

Originally Posted By: rayp
Quote:
it needs gravity code.
feel free todo ^^
I have a special surprise coming out soon tongue

Best regards
Posted By: Realspawn

Re: Any clear working example ? - 04/13/15 11:02

curious to see it and test it laugh rayp did give a good headstart laugh
Posted By: 3run

Re: Any clear working example ? - 04/13/15 11:40

Here you go grin
© 2024 lite-C Forums