2 registered members (AndrewAMD, Ayumi),
838
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Issue scripting jump animation
#373325
06/09/11 14:52
06/09/11 14:52
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Hey Everyone I've modified the Improved Player Movement from the wiki with a 3rd person camera. Because of that, I need my player to have animations when walking/running/jumping. Running the animation for walking/running is no problem, but I'm really struggling to get the animation to play correctly when jumping. Right now, if you press key_space, it begins the animation, but then stops. The jump continues, but with the walking animation (or standing animation, whichever is appropriate). I'm using STATES for the animation. I've been reading a lot of tutorials, and the manual. I think it might be because of the ANM_CYCLE mode, as the manual says it's for "Cyclic animation scene, like walking or running. Otherwise it's a noncyclic scene like jumping or shooting." So is there another mode that would play the entire jump animation cycle? If I just remove ANM_CYCLE, I get an error. Is there a noncyclic mode? Here's my jump STATE code:
if(key_space == 1)
{my.STATE = 3;}
if (my.STATE ==3)
{
var height = (key_space)*15*time_step;
my.ANIMATION += 1*height;
ent_animate(me,"jump",my.ANIMATION,ANM_CYCLE);
if(grounddist-minv(movedir.z*time_step, grounddist) == 0)
{
//jump
if(key_space)
{
movedir.z = -jumpacc;
}
}
}
Any help would be greatly appreciated! Emo
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Issue scripting jump animation
[Re: emo10001]
#373346
06/09/11 16:45
06/09/11 16:45
|
Joined: Aug 2009
Posts: 1,438 Spain
painkiller
Serious User
|
Serious User
Joined: Aug 2009
Posts: 1,438
Spain
|
you can use 0 instead of ANM_CYCLE
3D Gamestudio A8 Pro AMD FX 8350 4.00 Ghz 16GB RAM Gigabyte GeForce GTX 960 4GB
|
|
|
Re: Issue scripting jump animation
[Re: painkiller]
#373364
06/09/11 18:12
06/09/11 18:12
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Hehe...yeah I just finally figured that out. However, with it being in the rest of the script...it still just runs 1 frame of the animation, continues the jump with the standing or walking animation. I've also been moving it around a little. Now, when I load the level...I can walk/strafe/run...etc....but as soon as I hit key_space, it runs through the animation one time...and then I can't make any other movements. The level isn't crashing (as far as I can tell), but my player movement locks up. Heres my full code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
#define STATE skill1
#define ANIMATION skill2
var jump_percentage;
///////////////////////////////
function main()
{
//video_screen = 1;
detail_size = 2;
level_load("testgame.wmb");
}
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-150,10,50)); // camera position relative to the player
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_add(camera.x,ent.x); // add player position
vec_set(camera.pan,vector(ent.pan,-13,0)); // look in player direction, slighty down
wait(1);
}
}
action aPlayer()
{
camera_follow(me);
//Parameter
//var movespeed = 10.0/16.0;
var movespeed = 15;
var turnspeed = 13;
var fallacc = 3.68;
var jumpacc = 20;
//Temporary
VECTOR movedir;
vec_set(movedir, vector(0, 0, 0));
ANGLE rotdir;
vec_set(rotdir, vector(0, 0, 0));
var grounddist;
//determine player height
c_setminmax(my);
wait(1);
var feedheight = -my.min_z;
//adjust bounding box
my.min_x *= 0.7;
my.min_y *= 0.8;
my.min_z = 0;
my.max_x *= 0.7;
my.max_y *= 0.8;
my.max_z *= 0.8;
//start camera funtions
//updateCam(my);
proc_mode = PROC_EARLY;
while(1)
{
if (!key_cuu & !key_cud)
{my.STATE = 2;}
if (key_cuu ==1 | key_cud ==1 | key_ctrl ==1 | key_ins ==1)
{my.STATE = 1;}
if (my.STATE ==1)
{
//define key inputs
movedir.x = (key_cuu-key_cud)*(1+key_shift*2);
movedir.y = (key_ctrl-key_ins);
//define mouse motion
//rotdir.pan = -mouse_force.x;
rotdir.pan = (key_cul-key_cur);
//calculate speed
movedir.x *= movespeed*time_step;
movedir.y *= movespeed*time_step;
//calculate speed of movement
rotdir.pan *= turnspeed*time_step;
//rotate and move
vec_add(my.pan, rotdir);
c_move(my, vector(movedir.x, movedir.y, 0), nullvector, GLIDE|IGNORE_PASSABLE);
var distance = (key_cuu-key_cud | key_ctrl-key_ins)*15*time_step;
if (key_cuu ==1 | key_cud ==1) //walk forward-backward
{
my.ANIMATION += 1*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
}
if (key_ctrl ==1 | key_ins ==1) //strafe left-right
{
my.ANIMATION += 1*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
}
if (key_cuu ==1 & key_ins ==1)
{
my.ANIMATION -= 1*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
}
if (key_cuu ==1 & key_ctrl ==1)
{
my.ANIMATION -= 1*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
}
if (key_cud ==1 & key_ins ==1)
{
my.ANIMATION -= 1*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
}
if (key_cud ==1 & key_ctrl ==1)
{
my.ANIMATION -= 1*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
}
}
//check distance to ground
grounddist = c_trace(my.x, vector(my.x, my.y, my.z-10000), IGNORE_ME|IGNORE_PASSABLE)-feedheight;
if(grounddist > 0 || movedir.z < 0)
{
//gravity acceleration
movedir.z += fallacc*time_step;
}else
{
movedir.z = 0;
}
//apply gravity
my.z -= minv(movedir.z*time_step, grounddist);
if(grounddist-minv(movedir.z*time_step, grounddist) == 0)
{
if(key_space == 1)
{my.STATE = 3;}
if (my.STATE ==3)
{
while (1)
{
ent_animate(my,"jump",jump_percentage, 0);
jump_percentage += 7 * time_step;
wait (1);
}
if(grounddist-minv(movedir.z*time_step, grounddist) == 0)
{
//jump
movedir.z = -jumpacc;
}
}
}
if (my.STATE == 2)
{
my.pan += (key_cul-key_cur)*20*time_step;
var stand_percentage;
ent_animate(my,"stand",stand_percentage, ANM_CYCLE);
stand_percentage += 2 * time_step;
wait(1);
}
wait(1);
}
}
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Issue scripting jump animation
[Re: Pappenheimer]
#373381
06/09/11 19:56
06/09/11 19:56
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
I'm not sure where I would do that.
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Issue scripting jump animation
[Re: emo10001]
#373387
06/09/11 20:51
06/09/11 20:51
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Hmm...I'm pretty stuck. I've been messing with this for hours...still can't seem to get it. I'm sure it's something easy. At least it seems it shouldn't be that hard to do.
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Issue scripting jump animation
[Re: emo10001]
#373389
06/09/11 21:08
06/09/11 21:08
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Did you try adding "my.STATE = 1;" in the part of the jumping?
if(grounddist-minv(movedir.z*time_step, grounddist) == 0)
{
//jump
movedir.z = -jumpacc;
my.STATE = 1;
}
If that doesn't do the trick, try to rebuild the code from scratch, thinking about what is the beginning and what is to be add next, adding one thing at a time, testing, add another, testing, and so on.
|
|
|
Re: Issue scripting jump animation
[Re: Pappenheimer]
#373392
06/09/11 21:26
06/09/11 21:26
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Yeah, if I put my.STATE =1; there....nothing changes...still runs the jump animation one time and then I can't do anything else....all animations stop completely. It won't even go back to the "stand" animation (which is my.STATE 2). The level doesn't seem to lock up...but the player does.
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Issue scripting jump animation
[Re: emo10001]
#373770
06/12/11 19:33
06/12/11 19:33
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Ok....still using modified "Improve Player Movement" script from the wiki...I put the jump animation in a function. I can now get the jump animation to play all the way through....as long at the player is not moving otherwise. But if I'm moving backwards or forwards...and/or strafing...the walk animation overrides the jump animation. I've tried "if/else if"ing the button pushes to include the space bar...but to no avail. Anyone have any ideas...or a suggestion to try? I'm just using a terrain and the guard model...and this as my script:
///////////////////////////////
#include <acknex.h>
#include <default.c>
#include <mtlFX.c>
#define STATE skill1
#define ANIMATION skill2
///////////////////////////////
function main()
{
//video_screen = 1;
detail_size = 2;
level_load("testgame.wmb");
}
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-150,10,50)); // camera position relative to the player
vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
vec_add(camera.x,ent.x); // add player position
vec_set(camera.pan,vector(ent.pan,-10,0)); // look in player direction, slighty down
wait(1);
}
}
function jump()
{
//movedir.z = -jumpacc;
var jump_percentage = 0;
while(jump_percentage < 100)
{
ent_animate(my,"jump",jump_percentage,ANM_CYCLE);
jump_percentage += 10*time_step;
wait(1);
}
}
action move_guard()
{
camera_follow(me);
//Parameter
var movespeed = 10;
var turnspeed = 10;
var fallacc = 3.68;
var jumpacc = 15;
//Temporary
VECTOR movedir;
vec_set(movedir, vector(0, 0, 0));
ANGLE rotdir;
vec_set(rotdir, vector(0, 0, 0));
var grounddist;
//determine player height
c_setminmax(my);
wait(1);
var feedheight = -my.min_z;
//adjust bounding box
my.min_x *= 0.7;
my.min_y *= 0.8;
my.min_z = 0;
my.max_x *= 0.7;
my.max_y *= 0.8;
my.max_z *= 0.8;
proc_mode = PROC_EARLY;
while(1)
{
// //define key inputs
movedir.x = key_cuu-key_cud; //*(1+key_shift*2); FORWARD-BACKWARD
movedir.y = key_ctrl-key_ins; // STRAFE LEFT-RIGHT
// //calculate speed
movedir.x *= movespeed*time_step;
movedir.y *= movespeed*time_step;
my.pan += (key_cul-key_cur)*5*time_step; // TURN/ROTATE LEFT-RIGHT
c_move(my,vector(movedir.x, movedir.y, 0), nullvector, GLIDE|IGNORE_PASSABLE);
if(key_cuu | key_cud)
{
my.ANIMATION += 1*movedir.x;
ent_animate(my,"walk",my.ANIMATION,ANM_CYCLE);
}
else if(key_ins | key_ctrl)
{
my.ANIMATION += 1*movedir.y;
ent_animate(my,"walk", my.ANIMATION,ANM_CYCLE);
}
else if(key_cuu & key_ctrl | key_cuu & key_ins)
{
my.ANIMATION -= 1*movedir.x;
ent_animate(my,"walk", my.ANIMATION,ANM_CYCLE);
}
else if(key_cud & key_ctrl | key_cud & key_ins)
{
my.ANIMATION -= 1*movedir.x;
ent_animate(my,"walk", my.ANIMATION,ANM_CYCLE);
}
//check distance to ground
grounddist = c_trace(my.x, vector(my.x, my.y, my.z-10000), IGNORE_ME|IGNORE_PASSABLE)-feedheight;
if(grounddist > 0 || movedir.z < 0)
{
//gravity acceleration
movedir.z += fallacc*time_step;
}else
{
movedir.z = 0;
}
//apply gravity
my.z -= minv(movedir.z*time_step, grounddist);
if(grounddist-minv(movedir.z*time_step, grounddist) == 0)
{
//jump
if(key_space)
{
jump();
movedir.z = -jumpacc;
}
}
//
//
// if (my.STATE = 1)
// {
// var stand_percentage;
// ent_animate(my,"stand",stand_percentage, ANM_CYCLE);
// stand_percentage += 2 * time_step;
// }
wait(1);
}
}
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
Re: Issue scripting jump animation
[Re: emo10001]
#373792
06/12/11 23:20
06/12/11 23:20
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Ugh....ok....so I took the jump funtion out....added a state. And now...it runs through the entire jump animation (good!), but...doesn't actually raise the model up and down (the actual jump) until the animation is finished. Sooooo close... Any ides....Beuller? Here's the state:
if(my.STATE == 4)
{
var jump_percentage = 0;
while(jump_percentage < 100)
{
movedir.z = -jumpacc;
ent_animate(my,"jump",jump_percentage,0);
jump_percentage += 10*time_step;
wait(1);
}
if(!key_space)
{my.STATE = 1;}
}
Last edited by emo10001; 06/12/11 23:26.
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
|