HELP! Animations

Posted By: Harstad

HELP! Animations - 01/24/09 17:43

Ok, so I managed to make an modell in MED and made som bone-animations. Now I face a wall, I do not know how to implement this animation into the script. Though I know how to make gravity and such, I do not know c-move as I find the workshop a bit unfinished. Is there anyone that can help me implement the animations into the script, and make the player move with the animation?
Posted By: Harstad

Re: HELP! Animations - 01/24/09 17:47

Here's the code so far, as you can see, I'm experimenting with c-move:
#include <acknex.h>
#include <default.c>


VECTOR Player1_speed;
ENTITY* Player1;


BMAP* mouse_point = "mouse_pointer.bmp";
BMAP* new_panel_1 = "panel_1.bmp";
BMAP* main_menu = "main_menu.bmp";


PANEL* new_panel =
{
pos_x = -5;
pos_y = 400;
layer = 1;
bmap = new_panel_1;
button (10,10, "Exit_button.bmp", "Exit_button_checked.bmp", "Exit_button.bmp",quit_program, NULL, NULL);
flags = OVERLAY | VISIBLE;
}

function mouse_toggle()
{
mouse_map = mouse_point;
mouse_mode = 1;
while (1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
wait (1);
}
}

function quit_program()
{
sys_exit (NULL);
}



function main()
{
video_mode = 7;
video_screen = 1;
level_load ("Test_map_1.wmb");
wait (2);
Player1 = ent_create ("Person.mdl", vector(-500, -100, 0), NULL);
ph_setgravity (vector(0, 0, -200));
phent_settype (Player1, PH_RIGID, PH_BOX);
phent_setmass (Player1,3, PH_BOX);
phent_setfriction (Player1, 80);
phent_setdamping (Player1, 40, 40);
phent_setelasticity (Player1, 50, 20);
while (1)
{
camera.x = Player1.x -200;
camera.y = Player1.y;
camera.z = Player1.z+50 ;
on_m = mouse_toggle;
on_q = quit_program;
wait(1);
}
}

action move_me()
{
while (key_w)
{
c_move (Player1, nullvector, vector(0, 0, 50*time_step), GLIDE);
wait (1);
}
}


Posted By: Goodberry

Re: HELP! Animations - 01/24/09 19:38

Hey,

If you are using physics on your player model you can't play animations on it. In order to move your character while playing a walkcycle (is that what you ar trying to do?) you would play the animation on the character and move him forward with c-move.

To do this you need to run a script on your character which updates the animation every frame. So instead of

Player1 = ent_create ("Person.mdl", vector(-500, -100, 0), NULL);

write

Player1 = ent_create ("Person.mdl", vector(-500, -100, 0), playerscript);

and then make the function playerscript like so:

void playerscript
{

var anim_percentage = 0;

while(1)
{
anim_percentage += 2 * time_step;
ent_animate(me, "walk", anim_percentage, ANM_CYCLE);
c_move (Player1, nullvector, vector(0, 0, 50*time_step), GLIDE);

}

}

You should also look up the documentation for c_move in the manual, it has a complete script for moving a character.
Posted By: Harstad

Re: HELP! Animations - 01/24/09 23:16

I gone through it in parts, whenever I need something, I check with it first.
I'm getting confused by the "walk" in ent_animate(me, "walk", anim_percentage, ANM_CYCLE); what does it refer too?

for MED, its enough to make the animations, and then just use ent_create and then ent_animate to get him to do the animation?
Posted By: Crypton

Re: HELP! Animations - 01/25/09 09:15

if you would look up in the manual:

ent_animate(ENTITY* entity,STRING* scene,var percent,var mode)

String* scene reffers to the name of your scene.
If you create frames in MED you can name them. Such as walk1 walk2 walk3 etc.
That name without number is the scene string you have to use between quotes (as string is defined)
For bones I'm not sure. In manual, it says kinda that you should use ANM_ADD to add animations from precalled ent_anim functions. I think in some AUM there was a tutorial about this....? Just remeber I saw one somewhere.

Cheers!
Posted By: Harstad

Re: HELP! Animations - 01/25/09 10:56

ok, thanks that answers my question;)
Posted By: Harstad

Re: HELP! Animations - 01/26/09 19:17

Ok, so I managed to get the animations in and stuff, but I wonder, how do I get it so that when I hit w, he walks forward, but when I release it he gets to an halt with and blends into the idle animation?

function playerscript()
{
while(!key_w) wait(1);
while(1)
{
ent_animate(me, "walk", anim_percentage, ANM_CYCLE); //animates the player
anim_percentage += 10*time_step; // set the animation in motion
c_move(me,vector(10*time_step,0, 0), nullvector, GLIDE); //sets the player in movement
wait (1);
}
}

Posted By: Crypton

Re: HELP! Animations - 01/26/09 20:09

I'd do:
//Attach it inside WED to an object:
Code:
action playerscript()
{

while(1)
{
   if (key_w)
   {
   anim_percentage += (10*time_step)%100; //%100 keeps it inside 100 value
   ent_animate(me, "walk", anim_percentage, ANM_CYCLE); //animates the player
   }else{ //If no button, do the idle or stand or whatever:
   idle_precentage += (5*time_step)%100; //declare a second percentage variable for this!
   ent_animate(me, "idle", idle_percentage, ANM_CYCLE); //animates the player
   }
c_move(me,vector(10*time_step,0, 0), nullvector, GLIDE); //sets the player in movement

wait (1);
}
}


for movement I'd do a speed variable and make it's value according to buttons:

spdx = (key_w - key_a)*10*time_step;

The idea is that when you press W you get (1-0)*10*time_step which is like 10*timestep. Positive value to move forward. And when A is pressed you get
(0-1)*10*time which is -10*time_step a negative value to go backward f.i.
And then use it inside "relvector" x component in c_move.
Just go and search for tutorials. Such tricks and hints are covered there.

Cheers!
Posted By: Harstad

Re: HELP! Animations - 01/27/09 18:06

thanks, it helped alot:D every help I get brings me one step closer to my game;)
© 2024 lite-C Forums