Problem with c_trace and wait

Posted By: Luzifer

Problem with c_trace and wait - 01/20/08 21:05

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.
Posted By: Nems

Re: Problem with c_trace and wait - 01/20/08 23:41

I suspect vec_set(gun_target, Gun_muzzle); may be the prob (I'm no coder though) which means that the target sprite would be at the gun muzzle and not the gun_target and if its their but not passable, it would slow down your character.

Might need advanced coders to sort this for you

Set it to the pistol.x maybe.
Posted By: Futurulus

Re: Problem with c_trace and wait - 01/21/08 01:46

I think the code for the function is sound. The only thing I noticed was that you use naked skill names: what are skill3 and skill50 here?

The problem is probably in some other function, though. Check the player movement code and the crosshair creation code to make sure they don't block the player.

Also, does the function do what it is intended to do? i.e. does the crosshair appear in the right place, even though the player can't move? If it does, then you know it's not the player colliding with the crosshair.
Posted By: Luzifer

Re: Problem with c_trace and wait - 01/21/08 10:47

Thank you for your replies!

The crosshair works perfectly and it's not colliding with the player. Like I said, I narrowed it down to the c_trace. When I comment it, the movement works perfectly (the crosshair does not anymore, of course). Also if I put a wait(1); there it kind of works but with skipping frames. So it must be about timing somehow (the c_traces trace at the exact same time or something like that).

skill3 is the player's health and skill50 is the state of the gun draw animation cycle (so the dot appears when he's drawn his gun to a certain extent). I already replaced it with while(1), etc. so that's not the problem (it also works perfectly so far).
Posted By: Futurulus

Re: Problem with c_trace and wait - 01/21/08 17:51

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.
Posted By: Luzifer

Re: Problem with c_trace and wait - 01/22/08 00:02

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
}


Posted By: Luzifer

Re: Problem with c_trace and wait - 01/23/08 20:38

It does not matter how I create the crosshair-entity btw. Can as well be set in the WED, all the same.

So...anyone?
Posted By: raiden

Re: Problem with c_trace and wait - 01/24/08 00:07

Just curious as to what would happen in your situation if you used: IGNORE_SPRITES in the trace mode?

-raiden
Posted By: Luzifer

Re: Problem with c_trace and wait - 01/24/08 18:20

Nothing, as expected. I think I know where you are getting at, but I already said the crosshair does not collide with the player. It's on the wall, where it's supposed to be.

I'm really going nuts here, I don't know how to go on without solving this problem...
Posted By: Joozey

Re: Problem with c_trace and wait - 01/24/08 18:28

Code:

temp.z -= 4000;
check_inair = c_trace(my.x, temp, ignore_me|use_box);



Try adding ignore_passable here too
Posted By: flits

Re: Problem with c_trace and wait - 01/24/08 18:29

maby post a small demo that inside everthing to make it plausible
Posted By: Luzifer

Re: Problem with c_trace and wait - 01/25/08 12:35

Thanks, but didn't make a difference either. This is unbelievable. There seems to be no mistake but it doesn't work.
Posted By: Luzifer

Re: Problem with c_trace and wait - 01/26/08 14:50

Okay, now I got a preliminary solution. I replaced the c_trace in the crosshair function with A5's trace command. That is so weird. Maybe a bug in the engine?
© 2024 lite-C Forums