2 registered members (AndrewAMD, TipmyPip),
844
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Maybe I should have posted it here.
#311604
02/20/10 23:01
02/20/10 23:01
|
Joined: Oct 2009
Posts: 60
Tman
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2009
Posts: 60
|
Hey guys, New guy here with a script question I posted it in starting with GS but haven't gotten too many responses so I will post my question here. I have been using GS for about a month now and I have read the tuts and tried to follow along as best I could but I am having trouble with a jump code and was wondering if any one could help with the jump code so I could understand it better.
while(1)
{
var dist_down;
// adjust entity to the ground height, using a downwards trace
if(c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_ME | IGNORE_PASSABLE | USE_BOX) > 0)
dist_down= my.z + vFeet.z - target.z; // always place player's feet on the ground
else
dist_down = 0;
if(dist_down > 0)
{
dist_down = clamp(dist_down,0,accelerate(speed_down,10,0.1));
ent_blend("land",25,75);
}
else
speed_down = 0;
//move the entity forward
var distance =(key_cuu)* 25 *time_step;
distance = sign(distance)* (abs(distance) + 0.5 * dist_down);
c_move(me,vector(distance,0,0),vector(0,0,-dist_down),IGNORE_PASSABLE |GLIDE);
//rotate player with the left and right keys
my.pan += (key_cul-key_cur)*5* time_step;
//default state
if(my.STATE == 0)
{
my.ANIMATION += 2 *time_step;
ent_animate(me,"idleSWA",my.ANIMATION,ANM_CYCLE);
}
//the run state without the sword in hand
if(my.STATE ==1)
{
ent_blend("runWS",25,45);
//animate the player
my.ANIMATION += 15 * time_step;
ent_animate(me,"runWS",my.ANIMATION,ANM_CYCLE);
}
//pressing the move key to make him run with out the sword
//changing his state
if((key_cuu == 1)&& my.STATE == 0)
{
my.ANIMATION = 0;
my.STATE = 1;
}
else if((!key_cuu)&& my.STATE == 1)
{
my.ANIMATION = 0;
my.STATE = 0;
}
//take the sword out and put it in the hand.
if(my.STATE ==2)
{
my.ANIMATION += 5 *time_step;
ent_animate(me,"takeSWO",my.ANIMATION,0);
//blend the state from taking out the sword
//to the idle.
if(my.ANIMATION > 100)
{
ent_blend(my.STATE = 4,0,50);
}
}
//run with the sword in his hand
if(my.STATE == 3)
{
ent_blend("run",25,45);
//animate the player
my.ANIMATION += 15 * time_step;
ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
}
//idle with the sword in hand
if(my.STATE == 4)
{
my.ANIMATION += 2 *time_step;
ent_animate(me,"idleSWI",my.ANIMATION,ANM_CYCLE);
}
//putting the sword away
if(my.STATE == 5)
{
my.ANIMATION += 5 * time_step;
ent_animate(me,"putSWA",my.ANIMATION,NULL);
if(my.ANIMATION > 100)
{
ent_blend(my.STATE = 0,0,50);
}
}
//the attack state
if(my.STATE == 6)
{
my.ANIMATION += 4 * time_step;
ent_animate(me,"attack",my.ANIMATION,NULL);
}
if(my.STATE == 7)
{
jump_height = 75 * time_step;
jump_perct += 45 *time_step;
c_move(me,vector(0,0,jump_height),NULL,GLIDE);
ent_animate(me,"jump",jump_perct,0);
ent_blend("hang",0,25);
}
//press the key to change states
//take out the sword if you are in the idle state
//with the sword in sheath
if((key_t == 1)&& my.STATE == 0)
{
my.ANIMATION = 1;
my.STATE = 2;
}
//running and pull sword at the same time
if((key_cuu == 1)&& (key_t ==1) && my.STATE == 1)
{
my.STATE = 2;
}
//after changing states if you are trying to
//move with the sword in hand
if((key_cuu==1)&& my.STATE == 2)
{
my.ANIMATION = 1;
my.STATE = 3;
}
//if you have stopped moving
//play the idle with the sword in the hand
else if((key_cuu == 0)&& my.STATE == 3)
{
my.ANIMATION = 1;
my.STATE = 4;
}
//run with the sword in hand
if((my.STATE == 4) && key_cuu == 1)
{
my.ANIMATION = 1;
my.STATE = 3;
}
//when your idle is sword in hand
//and you want to put it away
if((key_p == 1) && my.STATE == 4)
{
my.ANIMATION = 1;
my.STATE = 5;
}
//now you have put the sword away
//go back to original state and start over again
if((my.STATE == 5) && key_cuu == 1)
{
my.ANIMATION = 1;
my.STATE = 1;
}
//Press the space key to make the player jump
if(key_space == 1 && my.STATE == 0)
{
my.ANIMATION = 1;
my.STATE = 7;
}
So if any could point me in the right direction with jump I would be greatly appreciative.
|
|
|
Re: Maybe I should have posted it here.
[Re: Tman]
#311613
02/20/10 23:59
02/20/10 23:59
|
Joined: May 2009
Posts: 1,816 at my pc (duh)
darkinferno
Serious User
|
Serious User
Joined: May 2009
Posts: 1,816
at my pc (duh)
|
var jump_height = 80;
var jump_target;
var nc_gravity = 2;
var playermovementz;
var move;
function NC_Movement_Ctrl()
{
while(1)
{
//my.Above_Ground=c_trace(vector(my.x,my.y,my.z - Z_Offset),vector(my.x,my.y,my.z-5000),IGNORE_ME|IGNORE_PASSABLE|USE_BOX);
my.Above_Ground=c_trace(my.x,vector(my.x,my.y,my.z-10000),USE_BOX|IGNORE_PASSABLE|IGNORE_ME);
my.Above_Ground=clamp(my.Above_Ground,0,100);
if(my.Above_Ground > 5)
{
accelerate(playermovementz,-nc_gravity*time_step,0.1);
}
else
{
playermovementz=-(my.Above_Ground/1.2)+2;
if((my.Above_Ground + playermovementz) > 5){playermovementz = - my.Above_Ground - 5;}
if(key_space == 1){jump_target = jump_height;}
}
if(jump_target > 5)
{
playermovementz = ( sqrt((jump_target)*nc_gravity) ) * time_step;
jump_target -= playermovementz;
c_move(my,vector(PlayerMoveSpeed*time_step*move,0,playermovementz),nullvector, USE_AABB | IGNORE_PASSABLE | GLIDE);
}
wait(1);
}
}
play around with the above, its a functioning code i just tested and am currently using, so it should work for you, you can ignore "PlayerMoveSpeed*time_step*move" from the c_move instruction, thats a part of my own movement code and may confuse you
Last edited by darkinferno; 02/21/10 00:00.
|
|
|
Re: Maybe I should have posted it here.
[Re: Tman]
#311866
02/21/10 21:50
02/21/10 21:50
|
Joined: Oct 2009
Posts: 60
Tman
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2009
Posts: 60
|
Here is the new code it works great just my camera looks gittery and could you take a look at tell me what else I may need to do?
#include <acknex.h>
#include <default.c>
#include "defines.c"
#define STATE skill1
#define ANIMATION skill2
//#define Above_Ground skill3
function ninja_move();
var jump_percentage;
var reached_height;
var dist_down;
var speed_down = 0;
var distance_to_ground;
var jump_height = 200;
var jump_target;
var nc_gravity = 2;
var playermovementz;
var move;
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-200,0,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);
}
}
action ninja_move()
{
camera_follow(me);
my.skill42 = floatv(25);
VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
my.STATE = 0;
while(1)
{
// adjust entity to the ground height, using a downwards trace
if(c_trace(my.x,vector(my.x,my.y,my.z-10000),USE_BOX|IGNORE_ME | IGNORE_PASSABLE) > 5)
dist_down= my.z + vFeet.z - target.z; // always place player's feet on the ground
else
dist_down = 0;
//dist_down = clamp(dist_down,0,100);
if((dist_down > 5))
{
dist_down = clamp(dist_down,0,accelerate(speed_down,-nc_gravity * time_step,0.1));
}
else
{
speed_down = -(dist_down/1.2)+2;
if((dist_down + speed_down)> 5)
{
speed_down = - dist_down - 5;
}
if(key_space == 1)
{
jump_target = jump_height;
}
}
if(jump_target > 5)
{
speed_down = (sqrt((jump_target)* nc_gravity))*time_step;
jump_target -= speed_down;
}
move_friction = 0.9;
//move the entity forward
var distance =(key_cuu)* 25 *time_step;
distance = sign(distance)* (abs(distance) + 0.5 * dist_down);
c_move(me,vector(distance,0,speed_down),vector(0,0,-dist_down),IGNORE_PASSABLE |GLIDE);
//rotate player with the left and right keys
my.pan += (key_cul-key_cur)*5* time_step;
my.pan += (key_cud) * 5 * time_step;
//default state
if(my.STATE == 0)
{
my.ANIMATION += 2 *time_step;
ent_animate(me,"idleSWA",my.ANIMATION,ANM_CYCLE);
}
//the run state without the sword in hand
if(my.STATE ==1)
{
ent_blend("runWS",25,45);
//animate the player
my.ANIMATION += 15 * time_step;
ent_animate(me,"runWS",my.ANIMATION,ANM_CYCLE);
}
//pressing the move key to make him run with out the sword
//changing his state
if((key_cuu == 1) && my.STATE == 0)
{
my.ANIMATION = 0;
my.STATE = 1;
}
else if((!key_cuu)&& my.STATE == 1)
{
my.ANIMATION = 0;
my.STATE = 0;
}
//take the sword out and put it in the hand.
if(my.STATE ==2)
{
my.ANIMATION += 5 *time_step;
ent_animate(me,"takeSWO",my.ANIMATION,0);
//blend the state from taking out the sword
//to the idle.
if(my.ANIMATION > 100)
{
ent_blend(my.STATE = 4,0,50);
}
}
//run with the sword in his hand
if(my.STATE == 3)
{
ent_blend("run",25,45);
//animate the player
my.ANIMATION += 15 * time_step;
ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
}
//idle with the sword in hand
if(my.STATE == 4)
{
my.ANIMATION += 2 *time_step;
ent_animate(me,"idleSWI",my.ANIMATION,ANM_CYCLE);
}
//putting the sword away
if(my.STATE == 5)
{
my.ANIMATION += 5 * time_step;
ent_animate(me,"putSWA",my.ANIMATION,NULL);
if(my.ANIMATION > 100)
{
ent_blend(my.STATE = 0,0,50);
}
}
//the attack state
if(my.STATE == 6)
{
my.ANIMATION += 4 * time_step;
ent_animate(me,"attack",my.ANIMATION,NULL);
}
//press the key to change states
//take out the sword if you are in the idle state
//with the sword in sheath
if((key_t == 1)&& my.STATE == 0)
{
my.ANIMATION = 1;
my.STATE = 2;
}
//running and pull sword at the same time
if((key_cuu == 1)&& (key_t ==1) && my.STATE == 1)
{
ent_blend(my.STATE = 2,25,50);
}
//after changing states if you are trying to
//move with the sword in hand
if((key_cuu==1)&& my.STATE == 2)
{
my.ANIMATION = 1;
my.STATE = 3;
}
//if you have stopped moving
//play the idle with the sword in the hand
else if((key_cuu == 0)&& my.STATE == 3)
{
my.ANIMATION = 1;
my.STATE = 4;
}
//run with the sword in hand
if((my.STATE == 4) && key_cuu == 1)
{
my.ANIMATION = 1;
my.STATE = 3;
}
//when your idle is sword in hand
//and you want to put it away
if((key_p == 1) && my.STATE == 4)
{
my.ANIMATION = 1;
my.STATE = 5;
}
//now you have put the sword away
//go back to original state and start over again
if((my.STATE == 5) && key_cuu == 1)
{
my.ANIMATION = 1;
my.STATE = 1;
}
wait(1);
}
}
Thanks for your help you are a life saver.
|
|
|
Re: Maybe I should have posted it here.
[Re: Tman]
#312089
02/23/10 07:05
02/23/10 07:05
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
try adding proc_mode = PROC_LATE; to your camera code.
function camera_follow(ENTITY* ent)
{
while(1)
{
vec_set(camera.x,vector(-200,0,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
proc_mode = PROC_LATE;
wait(1);
}
}
A8 com / A7 free
|
|
|
|