Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,280 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Problem with c_trace and wait #178923
01/20/08 21:05
01/20/08 21:05
Joined: Dec 2007
Posts: 34
L
Luzifer Offline OP
Newbie
Luzifer  Offline OP
Newbie
L

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] #178924
01/20/08 23:41
01/20/08 23:41
Joined: Mar 2003
Posts: 4,264
Wellington
Nems Offline

.
Nems  Offline

.

Joined: Mar 2003
Posts: 4,264
Wellington
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.

Re: Problem with c_trace and wait [Re: Nems] #178925
01/21/08 01:46
01/21/08 01:46
Joined: Dec 2006
Posts: 78
Nevada, USA
Futurulus Offline
Junior Member
Futurulus  Offline
Junior Member

Joined: Dec 2006
Posts: 78
Nevada, USA
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.

Re: Problem with c_trace and wait [Re: Futurulus] #178926
01/21/08 10:47
01/21/08 10:47
Joined: Dec 2007
Posts: 34
L
Luzifer Offline OP
Newbie
Luzifer  Offline OP
Newbie
L

Joined: Dec 2007
Posts: 34
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).

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 Offline
Junior Member
Futurulus  Offline
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
L
Luzifer Offline OP
Newbie
Luzifer  Offline OP
Newbie
L

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] #178929
01/23/08 20:38
01/23/08 20:38
Joined: Dec 2007
Posts: 34
L
Luzifer Offline OP
Newbie
Luzifer  Offline OP
Newbie
L

Joined: Dec 2007
Posts: 34
It does not matter how I create the crosshair-entity btw. Can as well be set in the WED, all the same.

So...anyone?

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 Offline
Member
raiden  Offline
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: raiden] #178931
01/24/08 18:20
01/24/08 18:20
Joined: Dec 2007
Posts: 34
L
Luzifer Offline OP
Newbie
Luzifer  Offline OP
Newbie
L

Joined: Dec 2007
Posts: 34
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...

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 Offline
Expert
Joozey  Offline
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
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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