|
problem with script, please help. (SOLVED!)
#314224
03/06/10 19:24
03/06/10 19:24
|
Joined: Mar 2010
Posts: 29
lollollollollol
OP
Newbie
|
OP
Newbie
Joined: Mar 2010
Posts: 29
|
hey, (this is page 1/2) I got this question about scripting/ level editing. I want to let the camera follow my playing character, let him walk on the ground(but when there is a ramp, he has to walk up the ramp in stead of walking through) and he may not walk through walls. So i have this code:
#include <acknex.h>
#include <default.c>
#define walk_percentage skill11
#define STATE skill1
#define STATE skill1
#define ANIMATION skill2
////////////////////////////////////////////////////////////////////
BMAP* cursor_pcx = "cursor.pcx";
BMAP* crosshair_pcx = "crosshair.pcx";
////////////////////////////////////////////////////////////////////
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);
}
}
action character_walking()
{
camera_follow(me);
VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
my.STATE = 1;
while (1)
{
// state 1: walking ////////////////////////////////////////////
if (my.STATE == 1)
{
// rotate the entity with the arrow keys
my.pan += (key_cul-key_cur)*5*time_step;
// move the entity forward/backward with the arrow keys
var distance = (key_cuu-key_cud)*5*time_step;
c_move(me, vector(distance,0,0), NULL, GLIDE);
// animate the entity
my.ANIMATION += 2*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
// adjust entity to the ground height, using a downwards trace
c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
my.z = hit.z - vFeet.z; // always place player's feet on the ground
}
}
}
function change_mouse_mode()
{
mouse_mode += 1;
mouse_mode %= 3;
if (1 == mouse_mode)
mouse_map = crosshair_pcx;
if (2 == mouse_mode)
mouse_map = cursor_pcx;
}
action zombie_bars()
{
while (1)
{
my.walk_percentage += 2 * time_step; // 3 = animation speed
ent_animate(me, "attack", my.walk_percentage, ANM_CYCLE); // "attack" animation loop
wait (1);
}
}
action zombie_fight_against_eachother()
{
while (1)
{
my.walk_percentage += 3 * time_step; // 3 = animation speed
ent_animate(me, "hit", my.walk_percentage, ANM_CYCLE); // "attack" animation loop
wait (1);
}
}
action zombie_fight_against_eachotherr()
{
while (1)
{
my.walk_percentage += 2.5 * time_step; // 3 = animation speed
ent_animate(me, "hit", my.walk_percentage, ANM_CYCLE); // "attack" animation loop
wait (1);
}
}
function main()
{
video_mode = 7;
level_load ("Huis.wmb");
ent_create("zombiek.mdl",vector(293,-107,-55), zombie_bars);
you = ent_create("zombiek.mdl",vector(425,106,-47), zombie_fight_against_eachother);
you.pan= 60;
you = ent_create("zombiek.mdl",vector(530,106,-47), zombie_fight_against_eachotherr);
you.pan= 240;
on_m = change_mouse_mode;
while (1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
camera.pan -= mouse_force.x;
camera.tilt += mouse_force.y;
wait (1);
}
camera.z = 120; // choose a convenient height
camera.tilt = -15; // and tilt angle for the camera
}
so if anyone knows why my script doesnt work, please respond. p.s. i havent loaded the character i will play with yet, but if that is nessecary, then could you please make this script with the main character in it.
Last edited by lollollollollol; 03/08/10 18:55.
|
|
|
Re: problem with script, please help.
[Re: lollollollollol]
#314276
03/07/10 12:49
03/07/10 12:49
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
This is how you load the zombie in the level:
you = ent_create("zombiek.mdl",vector(530,106,-47), zombie_fight_against_eachotherr);
It is the same with the player:
you = ent_create("zombiek.mdl",vector(530,106,-47), character_walking);
Did you have a look into the manual? Index 'ent_create'.
|
|
|
Re: problem with script, please help.
[Re: Pappenheimer]
#314379
03/08/10 06:53
03/08/10 06:53
|
Joined: Mar 2010
Posts: 29
lollollollollol
OP
Newbie
|
OP
Newbie
Joined: Mar 2010
Posts: 29
|
I did have a look in the manual, but how do i define , that my character can walk with the arrow keys, and that the camera is following him. I know how to load an entity, but not with this 2 functions. So if anyone is kind enough to tell me that please...
|
|
|
Re: problem with script, please help.
[Re: lollollollollol]
#314420
03/08/10 15:04
03/08/10 15:04
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
You already posted such a code, so I thought you already know about that. Look into it: key_cul, key cur, etc. are the inputs of the key. So something like the following means that the angle of the entity is changed by adding the 'signals' from the keys: my.pan += (key_cul-key_cur)*5*time_step; And the following lines mean that the variable distance is equal to the input of the result of the computed inputs of the keys at the right of '='. This means simply as I said in my post before that assigning this action to an entity is sufficient to control that entity.
action character_walking()
{
camera_follow(me);
VECTOR vFeet;
vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
my.STATE = 1;
while (1)
{
// state 1: walking ////////////////////////////////////////////
if (my.STATE == 1)
{
// rotate the entity with the arrow keys
my.pan += (key_cul-key_cur)*5*time_step;
// move the entity forward/backward with the arrow keys
var distance = (key_cuu-key_cud)*5*time_step;
c_move(me, vector(distance,0,0), NULL, GLIDE);
// animate the entity
my.ANIMATION += 2*distance;
ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);
// adjust entity to the ground height, using a downwards trace
c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
my.z = hit.z - vFeet.z; // always place player's feet on the ground
}
}
}
|
|
|
Re: problem with script, please help.
[Re: lollollollollol]
#314434
03/08/10 16:37
03/08/10 16:37
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
In your initial post you posted a script, and you ask whether someone knows why it isn't working for you.
But you didn't say, what didn't work. Did the level load? Did you see zombies fighting against each other?
If you say, yes, at least that worked, then you only need to paste the following line within the curly brackets within the function main(), after the level_load instruction:
you = ent_create("zombiek.mdl",vector(0,0,0), character_walking);
EDIT: Sorry, I posted too fast, forgot things that had to be changeed to make sense to you.
Last edited by Pappenheimer; 03/08/10 18:12.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|