Gamestudio Links
Zorro Links
Newest Posts
nba2king Latest Roster Update Breakdown
by joenxxx. 10/14/25 06:06
Help!
by VoroneTZ. 10/14/25 05:04
Zorro 2.70
by jcl. 10/13/25 09:01
ZorroGPT
by TipmyPip. 10/12/25 13:58
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 10/11/25 18:45
Reality Check results on my strategy
by dBc. 10/11/25 06:15
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (Grant, joenxxx), 9,921 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
joenxxx, Jota, krishna, DrissB, James168
19170 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[Lite-C] First Person Movement Code #186382
02/29/08 07:39
02/29/08 07:39
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hi, I'm looking for some code for first person movement including the camera script. Thanks in advance

Re: [Lite-C] First Person Movement Code [Re: PadMalcom] #186383
02/29/08 09:15
02/29/08 09:15
Joined: Mar 2003
Posts: 4,264
Wellington
Nems Offline

.
Nems  Offline

.

Joined: Mar 2003
Posts: 4,264
Wellington

Re: [Lite-C] First Person Movement Code [Re: Nems] #186384
02/29/08 09:35
02/29/08 09:35
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Yeah found this one already but this is actually... 3d person

Re: [Lite-C] First Person Movement Code [Re: PadMalcom] #186385
02/29/08 10:10
02/29/08 10:10
Joined: Nov 2007
Posts: 1,032
Croatia
croman Offline
Serious User
croman  Offline
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
Here you go. I'm using 1st and 3rd person camera. 1st is the main camera but 3rd is used for testing purposes (animation and movement). Just change camera with "t" on keyboard. Double click "w" for sprint. Jump isn't yet implemented.

Code:

#define gravity skill30
#define zoffset skill31
var running;

#define animate skill32
#define animate2 skill33
#define state skill34
#define currentframe skill35
#define blendframe skill36

#define nullframe -2
#define blend -1
#define stand 0
#define run 1
#define walk 2
#define walkSlow 3
#define walkBack 4
#define jump 5
#define fall 6

#define run_animation_speed 7

VECTOR speed;
var anm_perc;
var move_speed;
var sMove = 1;
var wcount;
var wcounter;
var get_tired;
var regen;

void pl_move();
void pl_camera();
void pl_animate(animation_speed);


// player action
action player1()
{
player = me;
my.material = MtlNormalMapped;

my.gravity = 6; // needed for
my.zoffset = 2; // gravity handling
c_setminmax(me);

while(player)
{
pl_animate(1);
pl_move();
pl_camera();
wait(1);
}
}

void sprint_fun()
{
if(key_w && wcount == 0){while(key_w){wait(1);}wcount = 1;}
while(wcount == 1 && regen == 0){
wcounter += 3 * time_step;
if(key_w && wcounter < 50){
sMove = 2;
}else{
sMove = 1;
}
if(wcounter > 30 || sMove == 2){
wcount = 0;
wcounter = 0;
}
wait(1);
}
}

// player move action
void pl_move()
{
if(key_w){sprint_fun();}
if(sMove == 2){get_tired += 3*time_step;}
if(get_tired > 300){sMove = 1;regen += 3*time_step;
if(regen > 120){regen = 0;get_tired = 0;}}

result = c_trace(my.x, vector(my.x,my.y,my.z-500), IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX);
speed.z = -(result - my.zoffset);

if(sMove == 1){
speed.x = (key_w - key_s) * 6 * time_step;
speed.y = (key_a - key_d) * 5 * time_step;
}
if(sMove == 2 && get_tired <= 300){
speed.x = (key_w - key_s) * 11 * time_step;
speed.y = (key_a - key_d) * 9 * time_step;
}
my.pan = camera.pan;

if(key_w && sMove == 1 && my.state != walk){my.blendframe = walk;}
if(key_w && sMove == 2 && my.state != run){my.blendframe = run;}
if(key_s && my.state != walkBack){my.blendframe = walkBack; speed.x += 2 * time_step;}
if(!key_w && !key_s && !key_a && !key_d && my.state != stand){my.blendframe = stand;}

c_move(me, speed.x, nullvector, IGNORE_PASSABLE | GLIDE);
}

// player animate function
void pl_animate(animation_speed)
{
if (animation_speed <= 0) animation_speed = 1;

if (my.state != blend && my.blendframe != nullframe)
{
my.animate2 = 0;
my.state = blend;
}

if (my.state == blend)
{
if (my.currentframe == stand) ent_animate(my,"stand",my.animate,ANM_CYCLE);
if (my.currentframe == run) ent_animate(my,"run",my.animate,ANM_CYCLE);
if (my.currentframe == walk) ent_animate(my,"walk",my.animate,ANM_CYCLE);
if (my.currentframe == walkBack) ent_animate(my,"walk",my.animate,ANM_CYCLE);
if (my.currentframe == walkSlow) ent_animate(my,"walk",my.animate,ANM_CYCLE);
if (my.blendframe == stand) ent_blend("stand",0,my.animate2);
if (my.blendframe == run) ent_blend("run",0,my.animate2);
if (my.blendframe == walk) ent_blend("walk",0,my.animate2);
if (my.blendframe == walkBack) ent_blend("walk",0,my.animate2);
if (my.blendframe == walkSlow) ent_blend("walk",0,my.animate2);

my.animate2 += 45 * time_step;

if (my.animate2 >= 100)
{
my.animate = 0;
my.state = my.blendframe;
my.blendframe = nullframe;
}
}

if (my.state == stand)
{
ent_animate(my,"stand",my.animate,ANM_CYCLE);
my.animate += 5 * animation_speed * time_step;
my.animate %= 100;
my.currentframe = stand;
}

if (my.state == run)
{
ent_animate(my,"run",my.animate,ANM_CYCLE);
my.animate += run_animation_speed * animation_speed * time_step;
my.animate %= 100;
my.currentframe = run;
}

if (my.state == walk)
{
ent_animate(my,"walk",my.animate,ANM_CYCLE);
my.animate += 7 * animation_speed * time_step;
my.animate %= 100;
my.currentframe = walk;
}

if (my.state == walkSlow)
{
ent_animate(my,"walk",my.animate,ANM_CYCLE);
my.animate += 5 * animation_speed * time_step;
my.animate %= 100;
my.currentframe = walkSlow;
}

if (my.state == walkBack)
{
ent_animate(my,"walk",my.animate,ANM_CYCLE);
my.animate -= 5 * animation_speed * time_step;
if(my.animate <= 0){my.animate += 100;}
my.currentframe = walkBack;
}
}

var camera_type;

// player camera function
void pl_camera()
{
if(key_t && camera_type == 0){while(key_t){wait(1);}camera_type = 1;}
if(key_t && camera_type == 1){while(key_t){wait(1);}camera_type = 0;}

if(camera_type == 0){
camera.genius = NULL;
camera.pan -= 15 * mouse_force.x * time_step;
camera.tilt += 15 * mouse_force.y * time_step;

camera.x = player.x - 200 * cos(camera.pan) * cos(camera.tilt);
camera.y = player.y - 200 * sin(camera.pan) * cos(camera.tilt);
camera.z = player.z - 200 * sin(camera.tilt) + 30;
}else{
camera.genius = me;
camera.pan -= 15 * mouse_force.x * time_step;
camera.tilt += 15 * mouse_force.y * time_step;

camera.x = player.x;
camera.y = player.y;
camera.z = player.z + 68;
}
}





Ubi bene, ibi Patria.
Re: [Lite-C] First Person Movement Code [Re: croman] #186386
02/29/08 10:57
02/29/08 10:57
Joined: Mar 2003
Posts: 4,264
Wellington
Nems Offline

.
Nems  Offline

.

Joined: Mar 2003
Posts: 4,264
Wellington
@ PadMalcom
Simpy remove the 3rd person aspect to leave only the camera at player.x etc, make your player invisible and you have a 1st person camera.

Re: [Lite-C] First Person Movement Code [Re: Nems] #186387
02/29/08 11:23
02/29/08 11:23
Joined: Nov 2007
Posts: 1,032
Croatia
croman Offline
Serious User
croman  Offline
Serious User

Joined: Nov 2007
Posts: 1,032
Croatia
The KH movement will not work for his type of game because the player rotates and it doesn't do straffing like in FPS.

I have posted a complete movement code with that kind of a camera + 3rd person camera.



Ubi bene, ibi Patria.
Re: [Lite-C] First Person Movement Code [Re: croman] #186388
02/29/08 11:50
02/29/08 11:50
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Thanks, I'll try it this evening!

Re: [Lite-C] First Person Movement Code [Re: PadMalcom] #186389
02/29/08 17:55
02/29/08 17:55
Joined: Mar 2003
Posts: 4,264
Wellington
Nems Offline

.
Nems  Offline

.

Joined: Mar 2003
Posts: 4,264
Wellington
@ cerbi_croman, the idea is to extract the relevant parts and use them a simple process thats pretty basic.

Re: [Lite-C] First Person Movement Code [Re: Nems] #186390
03/10/08 07:53
03/10/08 07:53
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline OP
Serious User
PadMalcom  Offline OP
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hey the code works great! But unfortunately when I step "onto" a tree, my player is raised into the sky. Think it depends on the GLIDE parameter in c_move. Someone got a solution for that?


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1