|
Any clear working example ?
#450334
04/12/15 20:04
04/12/15 20:04
|
Joined: Jul 2001
Posts: 4,801 netherlands
Realspawn
OP
Expert
|
OP
Expert
Joined: Jul 2001
Posts: 4,801
netherlands
|
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 I looked in the forum but the topics i found have dead links or no answer at all thank you
Last edited by Realspawn; 04/12/15 20:18.
|
|
|
Re: Any clear working example ?
[Re: Realspawn]
#450336
04/12/15 23:13
04/12/15 23:13
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
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.
/*
-------------------------------------------------------
---=[ 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!
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: Any clear working example ?
[Re: rayp]
#450337
04/12/15 23:48
04/12/15 23:48
|
Joined: Jul 2001
Posts: 4,801 netherlands
Realspawn
OP
Expert
|
OP
Expert
Joined: Jul 2001
Posts: 4,801
netherlands
|
i will give this a try and let you know how it turns out. It works although the character somehow floats above the ground so that's an issue ::) Great work this is really usefull
Last edited by Realspawn; 04/13/15 00:10.
|
|
|
Re: Any clear working example ?
[Re: Realspawn]
#450339
04/13/15 00:21
04/13/15 00:21
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
You setup players BBOX correct be4? If the level is a model, instead of "blocks", you set its flag, yes? Your welcome man. Ill post it in2 contributions then btw. Works? Cool! ...got a "scripting - run" last days
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: Any clear working example ?
[Re: Realspawn]
#450350
04/13/15 08:35
04/13/15 08:35
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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 it needs gravity code. Greets
|
|
|
|