Posted By: Mythran
Help with models - 10/02/06 12:02
I dont know if this is the right place, but since i have problems with models
i'm posting here.
My player dont detect the mdl files, like rocks. it goes right throw it and detects it only inside them. why does this happend? also my player is about 5 quants aboube the floor how can i get him to stay 0 quants in the floor?
Is there a way to colide only with the vertex?
thanks in adavamce.
Posted By: demiGod
Re: Help with models - 10/02/06 13:21
Assign my.polygon flag in the object properties for the non moving mdl entities. However it depends on the player movement code you are using. You must use c_move in order the collision detection works.
BTW, use c_trace to position the player on the floor. There is so many examples in the forum, 3DGS workshops and tutorials on that matter. Just search them.
Posted By: Mythran
Re: Help with models - 10/02/06 20:41
Thanks

i done it. but i continue to pass right throw the mdl temple i made :S
but not throw the crate. strange this, aint it? :S
i done it with the player it was this: my.z_offset = 0; (it was set to 6)
when i jump to the crate it stays about 10 quants abouve it. life's against me.
i'll continue to try. But if you have a clue please help me.
Thanks for helping me guys.
Posted By: seneca
Re: Help with models - 10/02/06 20:53
try adding ignore_models to your trace mode ie.
trace_mode = ignore_me+ignore_passable+ignore_models+use_box;
or if you are using c_trace
c_trace(my.x,temp,ignore_me|ignore_passable |ignore_models | use_box);
this may help, the gravity problem. i'm still thinking on the collision problem
Posted By: Mythran
Re: Help with models - 10/03/06 19:34
It almost worked. But when i get on crates, the player won't jump :S
I'm truly gratefull. Thanks a lot for your help, but i'll have to look at all the code, to see what's wrong. i saw other's player scripts, and they all have lots of trace_modes "my code" only have one.
Thanks again
Posted By: Mythran
Re: Help with models - 10/03/06 23:13
FUNCTION rotate_entity(rotate_angle,rotate_speed);
DEFINE nullframe,-2;
DEFINE blend,-1;
DEFINE stand,0;
DEFINE run,1;
DEFINE walk,2;
DEFINE jump,3;
DEFINE fall,4;
DEFINE attack_a,5;
DEFINE attack_b,6;
DEFINE attack_c,7;
DEFINE attack_d,8;
DEFINE attack_e,9;
DEFINE attack_f,10;
DEFINE move_x,skill22;
DEFINE move_y,skill23;
DEFINE move_z,skill24;
DEFINE force_x,skill25;
DEFINE force_y,skill26;
DEFINE force_z,skill27;
DEFINE velocity_x,skill28;
DEFINE velocity_y,skill29;
DEFINE velocity_z,skill30;
DEFINE animate,SKILL31;
DEFINE animate2,SKILL32;
DEFINE animblend,SKILL33;
DEFINE currentframe,SKILL34;
DEFINE blendframe,SKILL35;
DEFINE z_offset,SKILL50;
DEFINE jumping_mode,SKILL51;
DEFINE gravity,SKILL52;
DEFINE movement_mode,SKILL53;
DEFINE moving,SKILL54;
DEFINE hit_by_player,SKILL55;
DEFINE entity_type,SKILL56;
entity* target_enemy;
var camera_move_to[3];
var camera_distance = 200;
var camera_pan;
var camera_tilt;
var mouse_right_press = 0;
var mouse_left_press = 0;
var a_press = 0;
var combo_continue = 0;
var player_lock_on = 0;
var airborne_attack = 0;
var temp2[6];
ACTION attach_entity { //ACTION attach_weapon {
//player_weapon = my;
my.passable = on;
proc_late();
WHILE (you != null) {
vec_for_vertex(temp.x,you,13); //hand palm base
vec_for_vertex(temp2.x,you,10); //hand palm tip
vec_set(my.x,temp.x);
vec_diff(temp.x,temp2.x,temp.x);
vec_to_angle(temp.pan,temp.x);
vec_set(my.pan,temp.pan);
wait(1);
}
}
ACTION attach_armor { //ACTION attach_weapon {
//player_weapon = my;
my.passable = on;
proc_late();
WHILE (you != null) {
vec_for_vertex(temp.x,you,199); //hand palm base
vec_for_vertex(temp2.x,you,231); //hand palm tip
vec_set(my.x,temp.x);
vec_diff(temp.x,temp2.x,temp.x);
vec_to_angle(temp.pan,temp.x);
vec_set(my.pan,temp.pan);
wait(1);
}
}
ACTION player_action {
player = my;
//c_setminmax(me);
my.gravity = 6; //6
my.z_offset = 0;
my.shadow = on;
// ent_create("sword.mdl",my.x,attach_entity);
wait(1);
WHILE (1) { //the main loop
handle_gravity();
handle_movement();
handle_camera();
handle_animation(1);
wait(1);
}
}
FUNCTION handle_movement() {
temp.x = -1000;
temp.y = 0;
my.moving = 0;
IF (key_cuu == 1 && key_cud == 0 && key_cul == 0 && key_cur == 0) { temp.x = camera.pan; }
IF (key_cud == 1 && key_cuu == 0 && key_cul == 0 && key_cur == 0) { temp.x = camera.pan + 180; }
IF (key_cul == 1 && key_cud == 0 && key_cuu == 0 && key_cur == 0) { temp.x = camera.pan + 90; }
IF (key_cur == 1 && key_cud == 0 && key_cul == 0 && key_cuu == 0) { temp.x = camera.pan - 90; }
IF (key_cuu == 1 && key_cul == 1 && key_cur == 0 && key_cud == 0) { temp.x = camera.pan + 45; }
IF (key_cuu == 1 && key_cur == 1 && key_cul == 0 && key_cud == 0) { temp.x = camera.pan - 45; }
IF (key_cud == 1 && key_cul == 1 && key_cur == 0 && key_cuu == 0) { temp.x = camera.pan + 135; }
IF (key_cud == 1 && key_cur == 1 && key_cul == 0 && key_cuu == 0) { temp.x = camera.pan - 135; }
IF (temp.x != -1000) {
my.moving = 1;
IF (key_shift == 1) { temp.y = 10 * time; } ELSE { temp.y = 15 * time; }
}
IF (my.movement_mode == 0) {
my.move_x = fcos(temp.x,temp.y);
my.move_y = fsin(temp.x,temp.y);
}
IF (my.movement_mode == 1 || my.movement_mode == 2) {
temp.y = fsin((my.animate * 1.2) + 45,15 * time);
my.move_x = fcos(my.pan,temp.y);
my.move_y = fsin(my.pan,temp.y);
temp.y = 0;
IF (temp.x != -1000) { //if we need to rotate whilst attacking (the player is pressing keys to rotate)
temp.y = 1;
}
}
move_mode = ignore_passable + glide;
ent_move(nullvector,my.move_x);
result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
IF (result < 0) { my.z -= result; my.velocity_z = 0; }
IF (target_enemy == null) {
IF (temp.y > 0) { rotate_entity(temp.x,30); }
} ELSE {
vec_diff(temp2.x,target_enemy.x,my.x);
vec_to_angle(temp2.pan,temp2.x);
rotate_entity(temp2.pan,30);
}
IF (my.movement_mode == 0) {
my.gravity = 6;
IF (my.move_x != 0 || my.move_y != 0) { //if we are moving
IF (my.animblend == stand) { //if our current animation is stand
IF (key_shift == 1) { my.blendframe = walk; } ELSE { my.blendframe = run; }
}
IF (my.animblend == run && key_shift == 1) { my.blendframe = walk; }
IF (my.animblend == walk && key_shift == 0) { my.blendframe = run; }
} ELSE {
IF (my.animblend > stand && my.animblend != jump && my.animblend != fall) { //if we arn't moving and our current animation is walk or run, blend and cycle the stand animation
my.blendframe = stand;
}
}
IF (mouse_left == 0 && mouse_left_press == 1) { mouse_left_press = 0; }
IF (mouse_left == 1 && mouse_left_press == 0 && my.animblend >= stand) {
mouse_left_press = 1;
my.blendframe = attack_a;
IF (my.jumping_mode == 1) {
airborne_attack = 1;
} ELSE {
airborne_attack = 0;
}
my.movement_mode = 1;
combo_continue = 0;
}
IF (key_a == 0 && a_press == 1) { a_press = 0; } ///////////////
IF (key_a == 1 && a_press == 0) {
IF (player_lock_on == 0) {
vec_set(temp.x,vector(360,180,250)); //replace c_scan with these 2 lines in versions of gamestudio below 6.4
result = scan_entity(player.x,temp);
IF (you != null) {
IF (you.entity_type == 2) { //make sure you've scanned an enemy
player_lock_on = 1;
target_enemy = you;
}
}
} ELSE {
player_lock_on = 0;
target_enemy = null;
}
a_press = 1;
}
}
IF (my.movement_mode == 1) {
IF (my.jumping_mode != 10) {
my.jumping_mode = 0;
} ELSE {
IF (my.animate >= 60 && my.animblend >= stand) { my.jumping_mode = 0; }
}
IF (mouse_left == 0 && mouse_left_press == 1) { mouse_left_press = 0; }
IF (mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) { mouse_left_press = 1; combo_continue = 1; }
}
IF (my.movement_mode == 2) {
my.jumping_mode = 0;
IF (mouse_left == 0 && mouse_left_press == 1) { mouse_left_press = 0; }
IF (mouse_left == 1 && mouse_left_press == 0 && my.animate >= 30 && combo_continue == 0) { mouse_left_press = 1; combo_continue = 1; }
}
}
FUNCTION handle_gravity() {
trace_mode = ignore_me + ignore_sprites+ ignore_passable + ignore_models + use_box;
result = trace(vector(my.x,my.y,my.z - my.z_offset),vector(my.x,my.y,my.z - 4000));
IF (result < 3) {
IF (my.jumping_mode == 0) {
my.force_z = -1 * result;
IF (mouse_right == 0 && mouse_right_press == 1) { mouse_right_press = 0; }
IF (mouse_right == 1 && mouse_right_press == 0 && my.movement_mode == 0 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) {
mouse_right_press = 1;
my.jumping_mode = 1;
my.force_z = 20; //25
my.blendframe = jump;
my.animate2 = 0;
my.animblend = blend;
}
}
IF (my.jumping_mode == 2 || my.jumping_mode == 3) { my.jumping_mode = 0; }
} ELSE {
IF (my.jumping_mode == 2) {
IF (result > 120) {
my.animate = 60;
my.jumping_mode = 3;
} ELSE {
my.jumping_mode = 0;
}
}
IF (my.jumping_mode == 3 && result <= 120) { my.jumping_mode = 0; }
IF (my.jumping_mode == 0 && my.movement_mode == 0) {
IF (result > 120 && my.animblend >= stand && my.animblend != jump && my.animblend != fall) {
my.jumping_mode = 3;
my.blendframe = fall;
my.animate2 = 0;
my.animblend = blend;
}
}
my.force_z -= my.gravity * time;
my.force_z = max(-30,my.force_z);
IF (my.movement_mode == 2) { my.force_z = 0; }
}
my.velocity_z += (time * my.force_z) - (min(time*0.7,1) * my.velocity_z);
my.move_z = my.velocity_z * time;
}
//////////////////////////////
//Stable/rigid camera collision
//////////////////////////////
FUNCTION handle_camera() {
camera.pan -= mouse_force.x * 12 * time;
camera.tilt += mouse_force.y * 8 * time;
camera.tilt = clamp(camera.tilt,-30,10);
temp = fcos(camera.tilt,-camera_distance);
vec_set(camera.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera.tilt,-camera_distance)));
vec_diff(temp.x,camera.x,my.x); //find the vector from the player to the camera
vec_normalize(temp.x,16); //get the magnitude of it's vector to 16 quants and store it in temp
vec_add(temp.x,camera.x); //add the vector (from player to camera) of a magnitude of 16 quants and add it to the camera's position.
trace_mode = ignore_me+ignore_passable+ignore_models;
result = trace(my.x,temp.x); //trace from the player to 16 quants behind the camera.
IF (result > 0) {
vec_diff(temp.x,my.x,target.x); //find the vector from the point the trace hit to the player
vec_normalize(temp.x,16); //get the magnitude of this vector to 16 quants and store in temp
vec_set(camera.x,target.x); //place the camera at the trace hit point
vec_add(camera.x,temp.x); //move the camera away from the wall by the vector temp, 16 quants towards the player
}
}
//////////////////////////////
//Smooth camera collision
//////////////////////////////
/*FUNCTION handle_camera() {
camera_pan -= mouse_force.x * 12 * time;
camera_tilt += mouse_force.y * 8 * time;
camera_tilt = clamp(camera_tilt,-30,10);
camera.pan = camera_pan;
temp = fcos(camera_tilt,-camera_distance);
vec_set(camera_move_to.x,vector(my.x + fcos(camera.pan,temp),my.y + fsin(camera.pan,temp),my.z + 20 + fsin(camera_tilt,-camera_distance)));
temp = min(1,0.5 * time); //changing 0.5 will change how fast the camera moves, at 1 places us at target, this value is what allows the smooth movement
camera.x += temp*(camera_move_to.x - camera.x);
camera.y += temp*(camera_move_to.y - camera.y);
camera.z += temp*(camera_move_to.z - camera.z);
vec_diff(temp.x,camera.x,my.x);
vec_normalize(temp.x,16);
vec_add(temp.x,camera.x);
trace_mode = ignore_me + ignore_passable + ignore_models;
IF (trace(my.x,temp.x) > 0) {
vec_diff(temp.x,my.x,target.x);
vec_normalize(temp.x,16);
vec_set(camera.x,target.x);
vec_add(camera.x,temp.x);
}
vec_diff(temp.x,my.x,camera.x);
vec_to_angle(camera.pan,temp.x);
}*/
FUNCTION rotate_entity(rotate_angle,rotate_speed) {
IF (my.pan == rotate_angle) { return; }
result = ang(rotate_angle - my.pan);
IF (result > 0) { my.pan += rotate_speed * time; }
IF (result < 0) { my.pan -= rotate_speed * time; }
IF (ang(rotate_angle - my.pan) < 0 && result > 0) { my.pan = rotate_angle; }
IF (ang(rotate_angle - my.pan) > 0 && result < 0) { my.pan = rotate_angle; }
}
Here's my player code. I must say this is a great script indeed. But there's something wrong with the script. I tryed to place the trace_mode everyone, but when he jumps to the crates he cant jump. and if i remove the +ignore_models
he stills stays about 10 quants abouve the crate. can someone PLEASE PLEASE tell me whats wrong with these?
Thanks