|
Re: Issue scripting jump animation
[Re: Pappenheimer]
#373835
06/13/11 13:49
06/13/11 13:49
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Yeah...I've been trying all kinds of combinations. If I replace "while" with "if", the animation stops after the first frame and if I'm in the process of walking also, goes back to the walking animation before the jump is finished. If I take out the "wait", it goes through half the animation and my player "climbs" higher and higher until key_space is released. Very strange.
I know it's got to be some combination of something...
"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: MrGuest]
#373853
06/13/11 17:37
06/13/11 17:37
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Yeah that's what I've done now (at least I think I've done) My state now looks like this:
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;
}
}
The "movedir.z = -jumpacc;" is the actual jump code. But I'm getting the same results. It runs through the jump animation first, then raises and lowers the player, instead of doing them both at the same time.
"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: MrGuest]
#375580
06/26/11 17:04
06/26/11 17:04
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Ok...I'm bumping this as I still can't get this to work. I'm really struggling with this and I feel like I'm REALLY close. Everything is working correctly now except for the fact that, when I press the Space Bar and the code moves to STATE 4, the model goes through the jumping animation first, and THEN the model actually moves up and down. I still can't get them to both happen at the same time. I understand c_move and what it does, and it's in the code at line 77, however, if I understand this correctly, it's NOT what's actually making the player move up and down...that bit is the "movedir.z = -jumpacc;" part of the code...right? Keep in mind, this is using the "Improved Player Movement" code from the wiki...all I'm trying to do is add animations for the 3rd party camera.
http://www.opserver.de/wiki/index.php/Improved_Player_Movement
Why this isn't working...is really boggling me. Any help would be so appreciated! Here's my entire code:
///////////////////////////////
#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("templatetest.WMB");
wait(2);
}
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 player_move()
{
camera_follow(me);
if(key_cuu ==0 | key_cud ==0 | key_cul ==0 | key_cur ==0 | key_ins ==0 | key_ctrl ==0 | key_space ==0)
{my.STATE = 1;}
//Parameter
var movespeed = 10;
var turnspeed = 10;
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.4;
my.min_y *= 0.8;
my.min_z = 0;
my.max_x *= 0.4;
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.STATE = 2;
}
if(key_ins | key_ctrl)
{
my.STATE = 3;
}
if(key_cuu & key_ctrl | key_cuu & key_ins)
{
my.STATE = 2;
}
if(key_cud & key_ctrl | key_cud & key_ins)
{
my.STATE = 2;
}
//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)
{
my.STATE = 4;
}
}
if(my.STATE == 1)
{
var stand_percentage;
ent_animate(my,"stand",stand_percentage, ANM_CYCLE);
stand_percentage += 2 * time_step;
}
if(my.STATE == 2)
{
my.ANIMATION += 1*movedir.x;
ent_animate(my,"walk",my.ANIMATION,ANM_CYCLE);
if(!key_cuu | !key_cud | !key_cul | !key_cur | !key_ins | !key_ctrl | !key_space)
{my.STATE = 1;}
}
if(my.STATE == 3)
{
my.ANIMATION += 1*movedir.y;
ent_animate(my,"walk",my.ANIMATION,ANM_CYCLE);
if(!key_cuu | !key_cud | !key_cul | !key_cur | !key_ins | !key_ctrl | !key_space)
{my.STATE = 1;}
}
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;
}
}
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 (BIG IMPROVEMENT!!! )
[Re: emo10001]
#375594
06/26/11 18:31
06/26/11 18:31
|
Joined: Jun 2008
Posts: 37 Oklahoma City, OK
emo10001
OP
Newbie
|
OP
Newbie
Joined: Jun 2008
Posts: 37
Oklahoma City, OK
|
Ok! I just made a major step! Thank you Mr. Guest for reminding me to keep looking at c_move. I added it a second time in my STATE 4. Made the z vector the "movedir.z". Then had to add another while loop for the jump_percentage. It's not perfect...but good enough for now. My only issue now is that the jump animation finishes before the player get's back to the ground. It actually finishes as the top of the jump, and the the player drops back down with either the walking animation (if the player is walking and jumping) or the standing animation (if the player was just standing and then jumping). If anyone has any suggestions on getting the jump animation to finish as the player is landing...instead of at the top of the jump...please feel free to suggest! Here's the new code:
///////////////////////////////
#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("templatetest.WMB");
wait(2);
}
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 player_move()
{
camera_follow(me);
if(key_cuu ==0 | key_cud ==0 | key_cul ==0 | key_cur ==0 | key_ins ==0 | key_ctrl ==0 | key_space ==0)
{my.STATE = 1;}
//Parameter
var movespeed = 10;
var turnspeed = 10;
var fallacc = 3.68;
var jumpacc = 5;
//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.4;
my.min_y *= 0.8;
my.min_z = 0;
my.max_x *= 0.4;
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.STATE = 2;
}
if(key_ins | key_ctrl)
{
my.STATE = 3;
}
if(key_cuu & key_ctrl | key_cuu & key_ins)
{
my.STATE = 2;
}
if(key_cud & key_ctrl | key_cud & key_ins)
{
my.STATE = 2;
}
//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)
{
my.STATE = 4;
}
}
if(my.STATE == 1)
{
var stand_percentage;
ent_animate(my,"stand",stand_percentage, ANM_CYCLE);
stand_percentage += 2 * time_step;
}
if(my.STATE == 2)
{
my.ANIMATION += 1*movedir.x;
ent_animate(my,"walk",my.ANIMATION,ANM_CYCLE);
if(!key_cuu | !key_cud | !key_cul | !key_cur | !key_ins | !key_ctrl | !key_space)
{my.STATE = 1;}
}
if(my.STATE == 3)
{
my.ANIMATION += 1*movedir.y;
ent_animate(my,"walk",my.ANIMATION,ANM_CYCLE);
if(!key_cuu | !key_cud | !key_cul | !key_cur | !key_ins | !key_ctrl | !key_space)
{my.STATE = 1;}
}
if(my.STATE == 4)
{
var jump_percentage = 0;
while(jump_percentage < 100)
{
movedir.z = jumpacc*time_step;
c_move(my,vector(movedir.x, movedir.y, movedir.z), nullvector, GLIDE|IGNORE_PASSABLE);
my.pan += (key_cul-key_cur)*5*time_step;
ent_animate(my,"jump",jump_percentage,0);
jump_percentage += 10*time_step;
wait(1);
}
while(jump_percentage > 1)
{
jump_percentage = 0;
my.STATE = 1;
wait(1);
}
}
wait(1);
}
}
"To one who has faith, no explanation is necessary. To one without faith, no explanation is possible." - St. Thomas Aquinas
|
|
|
|