1 registered members (AndrewAMD),
1,280
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Problem with c_trace and wait
#178923
01/20/08 21:05
01/20/08 21:05
|
Joined: Dec 2007
Posts: 34
Luzifer
OP
Newbie
|
OP
Newbie
Joined: Dec 2007
Posts: 34
|
Hello everyone, I got a really weird problem that I want to share with you. For my game I use a sprite that serves as a laser sight to the player's gun (well, I call it crosshair...). Here's the code: Code:
function crosshair() { my.overlay = on; my.passable = on; my.facing = off; my.transparent = on; my.ambient = 255; my.scale_x = 0.5; my.scale_y = 0.5; my.scale_z = 0.5;
while (player.skill3 > 0) { if (player.skill50 == 100)
{my.invisible = off;}
else
{my.invisible = on; }
vec_set(gun_target, gun_muzzle); gun_target.x += 10000; // the weapon has a firing range of up to 10,000 quants vec_rotate(gun_target, pistol.pan); vec_add(gun_target, pistol.x);
c_trace(gun_muzzle,gun_target,ignore_passable|ignore_me|use_aabb);
my.x = target.x; my.y = target.y; my.z = target.z; vec_to_angle(my.pan, normal); // put on surface
wait(1); } } Unfortunately, as soon as I create the entity running this function, my player cannot move anymore. I narrowed the problem down to the c_trace in this function and its timing. If I add a "wait(1);" before the trace the problem does not occur but the game runs in slow-mo (because of the frame skip?). I tried to work something out with proc_late() but nothing happened. Anyone know how I go about this? Edit: Also notable is that I used the exact same function in another game where it worked fine. Must have to do with a more complicated move function for this which also uses more c_traces.
Last edited by Luzifer; 01/20/08 21:07.
|
|
|
Re: Problem with c_trace and wait
[Re: Luzifer]
#178927
01/21/08 17:51
01/21/08 17:51
|
Joined: Dec 2006
Posts: 78 Nevada, USA
Futurulus
Junior Member
|
Junior Member
Joined: Dec 2006
Posts: 78
Nevada, USA
|
Yeah, I think that confirms the problem's not in your "crosshair" function. Can you post the code that creates the crosshair entity? And maybe the player movement code, if it's not too long?
I don't believe the c_traces can happen at the same time. 3DGS is a cooperative multitasker, which means even though functions appear to be running at the same time, they are really "rotating," yielding to the next function at each wait() statement.
Last edited by Futurulus; 01/21/08 17:54.
|
|
|
Re: Problem with c_trace and wait
[Re: Futurulus]
#178928
01/22/08 00:02
01/22/08 00:02
|
Joined: Dec 2007
Posts: 34
Luzifer
OP
Newbie
|
OP
Newbie
Joined: Dec 2007
Posts: 34
|
Here a simplified version of only the movement code. The funny thing is move_mode 1 (ducking) works! If I press shift I can turn the player (other movement is not supposed to be possible in this mode). Just move_mode 0 (walking,jumping,etc.) doesn't work. Code:
while(my.skill3 > 0) {
////////////////////////////// // MOVEMENT //////////////////////////////
if (move_mode == 0) { //standard move_mode //get the keyboardinput my.skill21 = (key_pressed(key_forwards)-(key_pressed(key_backwards)/2))*my.skill1; if (my.skill 21 >= 0) {my.skill22 = (key_pressed(key_left)-key_pressed(key_right))*my.skill1;} else {my.skill 22 = 0;} //gravity vec_set(temp, my.x); temp.z -= 4000; check_inair = c_trace(my.x, temp, ignore_me|use_box); if (check_inair > 10) { // in air? friction = 0.1; fallforce = gravity; anim_mode = 5; } else { // ground if (normal.z < 0.2) //slide if too steep { fallforce = gravity; vec_set(force,vector(0,0,0)); } else { fallforce = 0; vec_set(force,vector(my.skill21,my.skill22,0)); } if (key_pressed(key_jump) == 0) && (space_press == 1) { space_press = 0; } if (key_pressed(key_jump) == 1) && (space_press == 0) && (shooting_pose == 0) { space_press = 1; jump_speed = 130; } if (shooting_pose == 0) {fallforce += jump_speed*time_step;} jump_speed = 0; //reset jump_speed friction = 0.7; } //get the mousemovement my.skill24 = -mouse_force.x*my.skill2*time_step*2; my.skill25 = mouse_force.y*my.skill2*time_step*2;
//add physics my.skill21 = time_step*force.x + max(1-time_step*friction,0)*my.skill21; my.skill22 = time_step*force.y + max(1-time_step*friction,0)*my.skill22; my.skill30 = time_step*fallforce + max(1-time_step*friction,0)*my.skill30; vec_set(my.dist_rel,vector(my.skill21*time_step,my.skill22*time_step,0)); vec_set(my.dist_abs,vector(0,0,my.skill30)); //turn and move the player move_min_z = 0.0; c_rotate(me,vector(my.skill24,0,0),glide|ignore_passable|ignore_passents); c_move(me,my.dist_rel,my.dist_abs,glide|ignore_passable|ignore_passents); } //End of move_mode 0
if (key_pressed(key_duck)) {move_mode = 1;} else {move_mode = 0;} //has to be changed for later move_modes...
if (move_mode == 1) { //duck move_mode anim_mode = 4; //gravity vec_set(temp, my.x); temp.z -= 4000; check_inair = c_trace(my.x, temp, ignore_me|use_box); if (check_inair > 10) { // in air? friction = 0.1; fallforce = gravity; anim_mode = 5; } else { // ground if (normal.z < 0.9) //slide if too steep { fallforce = gravity; } else { fallforce = 0; } fallforce = -2 * check_inair; friction = 0.7; } //get the mousemovement my.skill24 = -mouse_force.x*my.skill2*time_step*2; my.skill25 = mouse_force.y*my.skill2*time_step*2;
//add physics my.skill30 = time_step*fallforce + max(1-time_step*friction,0)*my.skill30; vec_set(my.dist_abs,vector(0,0,my.skill30)); //turn and move the player move_min_z = 0; c_rotate(me,vector(my.skill24,0,0),glide|ignore_passable|ignore_passents); c_move(me,vector(0,0,0),my.dist_abs,glide|ignore_passable|ignore_passents);
} //End of move_mode 1 }
|
|
|
Re: Problem with c_trace and wait
[Re: Luzifer]
#178930
01/24/08 00:07
01/24/08 00:07
|
Joined: Sep 2003
Posts: 281 Arkansas\USA
raiden
Member
|
Member
Joined: Sep 2003
Posts: 281
Arkansas\USA
|
Just curious as to what would happen in your situation if you used: IGNORE_SPRITES in the trace mode?
-raiden
"It doesn't matter if we win or lose, it's how we make the game."-------------------- Links: 3DGS for Dummies
|
|
|
Re: Problem with c_trace and wait
[Re: Luzifer]
#178932
01/24/08 18:28
01/24/08 18:28
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
Code:
temp.z -= 4000; check_inair = c_trace(my.x, temp, ignore_me|use_box);
Try adding ignore_passable here too
Last edited by Joozey; 01/24/08 18:33.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
|