Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
0 registered members (), 938 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Simple movement script to start you off... #59824
11/30/05 10:35
11/30/05 10:35
Joined: Aug 2001
Posts: 2,320
Alberta, Canada
William Offline OP
Expert
William  Offline OP
Expert

Joined: Aug 2001
Posts: 2,320
Alberta, Canada
I was recently asked for a simple movement script to start someone off. Since I had one lying around, I decided might as well share it here as well. This script works perfectly fine with model-model collisions since it's set up to use all the "c_" instructions properly. To use it, simply copy and paste this code at the bottom of your main script and apply the "playerdef" action to a dummy model in WED. This action then creates a model, rotates it according to the dummy model, then starts the movement. Be sure to check the playerdef action and place your own model name in the ent_create().

You may notice your model or the camera is in inversed directions, if this happens then simply turn your model 180 degrees in MED and save it again. Or, just change a few things in the script. When I created the script, I believe the model I tested with was pointed in the -x direction...

Code:

define tracekart, skill70;
define z_normal, skill71;
define g_type, skill72;
define height, skill73;
define z_target, skill74;
define maxTorque, skill75;

function ccamera()
{
var cam_dist = 320; //how far away?
var cam_hi = 100; //how high up?
var cam_changa[3];
var tilt_3rd = 16; //tilt the camera

while(1)
{
temp.x = -cam_dist;
temp.y = 0;
temp.z = 0;
vec_set(cam_changa.pan, my.pan);
vec_rotate(temp,cam_changa.pan);
vec_add(temp,my.x);
temp.z = my.z + cam_hi;

vec_set(camera.x, temp.x);
camera.pan = cam_changa.pan;
camera.roll = 0;
camera.tilt = - tilt_3rd;
wait(1);
}
}

//-------------------------movement-----------------------------------
function move_player()
{
var anormal[3];
var g_normal[3];
var f_normal[3];
var align_kart = 0.7; //how quickly the kart re-aligns with the ground normals

var move[3];
var turn_speed;//pan speed
var run_speed; //x-axis forward speed
var f_speed; //the forward speed constant
var slide_speed; //y-axis side speed
var turn_direction; //determines the negative or positive values of speed
var run_direction;
var slide_direction;

var hill_speed; //Contains the calculated hill velocity
var hill_time; //Contains how long you've been on the hill
var hill_factor; //Contains the slowdown factor from being on a hill

f_speed = 120;
run_speed = f_speed;
slide_speed = 30;
turn_speed = 1;

vec_set(my.pan, you.pan);
my.fat = on;
my.narrow = on;
c_setminmax(my);
my.polygon = off;
move_min_z = -1;
move_friction = 0;
Disable_Z_Glide = 0;

ccamera(); //call camera code
while(1)
{
if(key_a){turn_direction = 1;} if(key_d){turn_direction = -1;}
if(!key_a && !key_d) || (key_a == 1 && key_d == 1){turn_direction = 0;}

if(key_w){run_direction = 1;} if(key_s){run_direction = -1;}
if(key_s && key_w) || (key_s == 0 && key_w == 0) {run_direction = 0;}

if(key_shift && key_d){slide_direction = 1;} if(key_shift && key_a){slide_direction = -1;}
if(key_shift == 1) && (key_a == 1 && key_d == 1) || (key_shift == 0) && (key_a == 0 || key_d == 0){slide_direction = 0;}

vec_set(temp, my.x); temp.z -= 4000;
result = c_trace(my.x, temp.x, ignore_me+ignore_sprites+ignore_passents+ignore_passable+use_box);
my.z_normal = normal.z;
if(my.z_normal == 0){my.z_normal = 0.01;}
my.height = result;
if(target)//Find ground angle from normal
{
my.z_target = target.z;
if((normal.x != 0) || (normal.y != 0))
{
vec_set(anormal.pan ,nullvector);
anormal.pan = -my.pan;
vec_rotate(normal,anormal.pan);
anormal.tilt = -asin(normal.x);
anormal.roll = -asin(normal.y);
}
else
{
anormal.tilt = 0;
anormal.roll = 0;
}
}

hill_time = 3/my.z_normal;
if(hill_factor < hill_time){hill_factor += 1/my.z_normal * time;}else{hill_factor = 3/my.z_normal;}
if(hill_factor < 0){hill_factor = 3/my.z_normal;}
my.maxtorque = 2;
hill_speed = my.tilt * run_direction * hill_factor/my.maxtorque;

if(my.roll > 40){slide_direction = -2; if(turn_direction == -1){turn_direction = 0.2;}}
if(my.roll < -40){slide_direction = 2; if(turn_direction == 1){turn_direction = -0.2;}}

run_speed = f_speed - hill_speed;

move.tilt = ang(anormal.tilt - my.tilt) * 1 * time; //turn player according to calculated ground angle over time
move.roll = ang(anormal.roll - my.roll) * 1 * time;
move.pan = turn_direction * 4 * time;
c_rotate(my,move.pan,ignore_passable + ignore_passents + ignore_push + glide);

if(my.height > 40) //if the player is still in the air, move the player down
{
move.x = 0; //running speed
move.y = 0; //turn speed
move.z = -25 * time;
}
else
{
move.z = 0; // distance down
if(my.z_normal > 0.4)
{
vec_set(temp.x, vector(0,0,40)); temp.z = my.z_target + temp.z; temp.z = my.z - temp.z; temp.z = -temp.z;
c_move(my,nullvector,temp.x,ignore_me + ignore_passable + glide + ACTIVATE_TRIGGER);
}
}

move.x = run_speed * run_direction * time;
move.y = slide_speed * slide_direction * time;
vec_rotate(move.x, my.pan);
c_move(my,nullvector,move,ignore_passable + glide); //move using absolute coordinates
wait(1);
}
}

action playerdef
{
my.passable = on;
my.invisible = on;
ent_create("player.mdl", my.x, move_player);
}




Check out Silas. www.kartsilas.com

Hear my band Finding Fire - www.myspace.com/findingfire

Daily dev updates - http://kartsilas.blogspot.com/
Re: Simple movement script to start you off... [Re: William] #59825
12/01/05 04:31
12/01/05 04:31
Joined: Jun 2005
Posts: 734
Under your couch
Silent_Assassin Offline
Developer
Silent_Assassin  Offline
Developer

Joined: Jun 2005
Posts: 734
Under your couch
its good that you posted this William,

not many people know how to make a simple movement script even though if they looked in the shooter tutorial (1st part) on acknex unlimited they will find it


Visit us at www.m-tec-development.com WIP - Urban Conflict
Re: Simple movement script to start you off... [Re: William] #59826
12/01/05 05:51
12/01/05 05:51
Joined: Feb 2005
Posts: 276
S
sempronius Offline
Member
sempronius  Offline
Member
S

Joined: Feb 2005
Posts: 276
no jump

looks good.


Moderated by  adoado, checkbutton, mk_1, Perro 

Gamestudio download | chip programmers | 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