|
7 registered members (3run, miwok, AndrewAMD, Quad, TipmyPip, fairtrader, 1 invisible),
637
guests, and 2
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Gravity Problem
#75548
05/25/06 17:42
05/25/06 17:42
|
Joined: Apr 2006
Posts: 265
vartan_s
OP
Member
|
OP
Member
Joined: Apr 2006
Posts: 265
|
I'm having a problem which I've tried to solve for quite some time now, with no success. I made a trace code, which gives gravity and allows you to go through terrain, but when you touch the corner of a building you slowly rise to the top of the building! Apart from that it works fine; It only happens when you touch the corner. The ground variable becomes -1 exactly. Here is the code:
action player_entity { player = me; while (1) { vec_set (temp, my.x); temp.z -= 4000; trace_mode = ignore_passable + use_box + ignore_me + ignore_push; ground = trace (my.x, temp); if(ground < 10) {player_speed.z = -trace(my.x,temp);} else {player_speed.z -= gravity_entity;} if (ground <= 10) {player_speed.x = 15 * (key_w - key_s) * time; // move forward / backward player_speed.y = 10 * (key_a - key_d) * time; // strafe left / right } move_mode = ignore_you + ignore_passable; if ((key_space == on) && (ground < 10)) { player_speed.z = 7; } c_move(me, vector(player_speed.x,player_speed.y,player_speed.z),nullvector, glide + ignore_me); if ((key_d == on) || (key_a == on) || (key_s == on) || (key_w == on) || (ground > 10)) { if (weapon_in_play_acc_change < weapon_in_play_max_loss) {weapon_in_play_acc_change += weapon_in_play_acc_loss_movement;} } else { if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off)) { weapon_in_play_acc_change -= weapon_in_play_acc_gain; } } if ((mouse_left == on) && (weapon_ready == 1)) { snd_play (bullet_wav, 0, 0); while (weapon_in_play_pellets_change != 0) { weapon_in_play_pellets_change -= 1; push_factor_change -= 1; ent_create (bullet_mdl, my.pos, shoot_bullet); wait(1); } camera.tilt += weapon_in_play_up_recoil; push_factor_change = -weapon_in_play_pellets; weapon_ready = 0; weapon_become_ready(); weapon_in_play_pellets_change = weapon_in_play_pellets; if (weapon_in_play_acc_change < weapon_in_play_max_loss_moving) {weapon_in_play_acc_change += weapon_in_play_acc_loss;} } else { if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off)) { weapon_in_play_acc_change -= weapon_in_play_acc_gain; } }camera.x = player.x; camera.y = player.y; camera.z = player.z; player.pan = camera.pan; wait (1); } }
Only look at the part that looks at gravity. Disregard the rest. Thanks in advance, and sorry if its a noobish question!
|
|
|
Re: Gravity Problem
[Re: vartan_s]
#75549
05/25/06 19:08
05/25/06 19:08
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Something like that... Code:
var TraceDist = 4000; // set the distance for tracing
action player_entity { player = me; while (1) { vec_set (temp, my.x); temp.z -= TraceDist; trace_mode = ignore_passable + use_box + ignore_me + ignore_push; ground = c_trace(my.x, temp) + my.min_z; // by adding min_z, you get the distance from the "feet" of the model. Remove this if needed. if (ground <= 0) {ground += TraceDist;} // Here's the magic trick. Trace returns <= zero if the trace immediatly hits a solid. You want to tell it that it really didn't. ;) if (ground < 10) {player_speed.z = -ground;} // No need for another trace. ;) else {player_speed.z -= gravity_entity;} if (ground <= 10) { player_speed.x = 15 * (key_w - key_s) * time; // move forward / backward player_speed.y = 10 * (key_a - key_d) * time; // strafe left / right } if ((key_space == on) && (ground < 10)) { player_speed.z = 7; } move_mode = ignore_you + ignore_passable + glide; //Just another way to do it... c_move(me, vector(player_speed.x, player_speed.y, player_speed.z), nullvector, move_mode); if ((key_d == on) || (key_a == on) || (key_s == on) || (key_w == on) || (ground > 10)) { if (weapon_in_play_acc_change < weapon_in_play_max_loss) {weapon_in_play_acc_change += weapon_in_play_acc_loss_movement;} } else { if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off)) { weapon_in_play_acc_change -= weapon_in_play_acc_gain; } } if ((mouse_left == on) && (weapon_ready == 1)) { snd_play (bullet_wav, 0, 0); while (weapon_in_play_pellets_change != 0) { weapon_in_play_pellets_change -= 1; push_factor_change -= 1; ent_create (bullet_mdl, my.pos, shoot_bullet); wait(1); } camera.tilt += weapon_in_play_up_recoil; push_factor_change = -weapon_in_play_pellets; weapon_ready = 0; weapon_become_ready(); weapon_in_play_pellets_change = weapon_in_play_pellets; if (weapon_in_play_acc_change < weapon_in_play_max_loss_moving) {weapon_in_play_acc_change += weapon_in_play_acc_loss;} } else { if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off)) { weapon_in_play_acc_change -= weapon_in_play_acc_gain; } } camera.x = player.x; camera.y = player.y; camera.z = player.z; player.pan = camera.pan; wait (1); } }
Last edited by xXxGuitar511; 05/26/06 15:47.
xXxGuitar511 - Programmer
|
|
|
Re: Gravity Problem
[Re: vartan_s]
#75551
05/26/06 15:49
05/26/06 15:49
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
I didn't know you were using a model for terrain, that kinda changes things a bit...
change the trace() to a c_trace. Do not use ent_move(), You have to use c_move().
*-Updated changes in blue ^ (just the "C_" on C_TRACE())
xXxGuitar511 - Programmer
|
|
|
Re: Gravity Problem
[Re: xXxGuitar511]
#75552
06/06/06 08:45
06/06/06 08:45
|
Joined: Mar 2006
Posts: 724 the Netherlands
Frits
User
|
User
Joined: Mar 2006
Posts: 724
the Netherlands
|
My player also keeps falling through the terrain (I have changed the terain into a model). I tried to solve this problem with the c_trace, but when I include the line: my.fall_distance = c_trace(my.x,temp,trace_mode)+my.min_z; the player keeps falling through the terrain. When I include the line: if(my.fall_distance<=0) {my.fall_distance+=trace_dist;} the player can't move anymore. Here is my Code:
//------------------- // player move action //-------------------
//uses: Walk_Anm_Speed, Run_Anm_Speed, Strafe_Anm_Speed, Jump_Walk_Run, //uses: Battery, Armor, Health, Ammo, Battery_max, Armor_max, Health_max, Ammo_max, Keys, falling, //uses: fall_distance, jumping, jump_hight, idle_percent, walk_percent, run_percent, //uses: land_percent, jump_percent, temptilt, //uses: move_vec_x, move_vec_y, move_vec_z action player_move { player=me; wait(2); my.falling=0; //not falling my.jumping=0; //not jumping my.jump_hight=0; //jump hight=0 my.idle_percent=0; my.walk_percent=0; my.run_percent=0; my.land_percent=0; my.jump_percent=0; my.temptilt=0; camera.genius=player; shift_sense=int(my.run_anm_speed); my.enable_scan = ON; my.event=player_events;
while(my.health>0) { vec_set(temp,my.x); temp.z-=trace_dist; trace_mode=ignore_me+ignore_sprites+ignore_passable+activate_sonar+use_box; my.fall_distance = trace(my.x,temp); // original line // my.fall_distance = c_trace(my.x,temp,trace_mode)+my.min_z; // if(my.fall_distance<=0) {my.fall_distance+=trace_dist;} // check if jumping if (my.jumping !=0) { jump_handling(); }
// check if falling fall_handling();
// check if player pressed jump X and isn't already juping or falling if (key_x) { if(my.jumping==0 && my.falling==0 && my.fall_distance<1) { my.jumping=1+key_shift; //if holding shift key when hit jump means we were running my.move_vec_z=20*time; //starting jump velocity } } // if not jumping or falling we can move if(!my.falling && my.jumping==0) //if falling=0 then !falling=-1, or true that I'm not falling { my.move_vec_x=(key_force.y)*int(my.walk_anm_speed)*time; my.move_vec_y=(key_comma-key_period)*int(my.strafe_anm_speed)*time; //strafing } // turn players facing if(mouse_mode==1) { player.pan=(player.pan-(key_force.x)*5*time); } else { player.pan=(player.pan-(key_force.x+mouse_force.x)*5*time)%360; } // animations // animate jump if (my.jumping !=0) { jump_animate(); } else //other animations { if (my.falling == 1) // animate falling { fall_animate(); } else // animate stand walk and run { If (my.move_vec_x == 0 && my.move_vec_y == 0) // stand { stand_animate(); } else // our movement animations will go here { if (key_shift) // either shift key is being pressed run aniamtion { run_animate(); } else // shift key is NOT being pressed so we are walking { walk_animate(); } } } } // entity moves move_mode=ignore_you+ignore_passable+ignore_push+activate_trigger+glide; ent_move(my.move_vec_x,NULLVECTOR); update_camera(); wait(1); } }
I hope someone can help me with this problem. Regards, Frits
I like to keep scripting simple, life is hard enough as it is. Regards, Frits
|
|
|
Re: Gravity Problem
[Re: Frits]
#75553
06/06/06 18:17
06/06/06 18:17
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Before you add min_z to fall_distance, make sure that the trace did not return 0 (hit nothing) or 1 (in ground - or somethin like that). like this: Code:
my.fall_distance = c_trace(my.x, temp, trace_mode); if (my.fall_distance == 0) {my.fall_distance = trace_dist;} my.fall_distance += my.min_z;
NEW: Ok. I updated the code a bit. Just put this at the beginning of your while() loop. Or at least before anything that uses the trace_distance variable.
Last edited by xXxGuitar511; 06/07/06 15:42.
xXxGuitar511 - Programmer
|
|
|
Re: Gravity Problem
[Re: xXxGuitar511]
#75556
06/07/06 16:05
06/07/06 16:05
|
Joined: Mar 2006
Posts: 724 the Netherlands
Frits
User
|
User
Joined: Mar 2006
Posts: 724
the Netherlands
|
Thanks, I will try it out tomorrow.
Regards, Frits
I like to keep scripting simple, life is hard enough as it is. Regards, Frits
|
|
|
Re: Gravity Problem
[Re: Frits]
#75557
06/08/06 07:32
06/08/06 07:32
|
Joined: Mar 2006
Posts: 724 the Netherlands
Frits
User
|
User
Joined: Mar 2006
Posts: 724
the Netherlands
|
No, didn't help, still falling through the terrain model.
Regards, Frits
I like to keep scripting simple, life is hard enough as it is. Regards, Frits
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|