Why does it not fly? PLEASE HELP

Posted By: CD_saber

Why does it not fly? PLEASE HELP - 08/21/08 13:34

Hello,
i'm using an cscript version of the throw object code from the wiki(for a bow code). The strange thing is that it works fine when I do not use a player/camera code. But when I want to use my player code and press the throw key, the arrow is created but stays motionless in the air.. please can somebody help me, what is the problem?
here is both the throwing code and the player script:

function Phy_debug_throw()
{

var flyvec[3];
vec_set(earthgravity, vector(0,0, -386));
while(1)
{
if(mouse_left)
{
you = ent_create("pfeil.mdl",camera.pos,NULL);
c_setminmax(you);


vec_set(you.pan,camera.pan);
ph_setgravity(earthgravity);


phent_settype(you,PH_RIGID,PH_BOX);
phent_setmass(you,2,PH_BOX);
phent_setelasticity(you,5,100);
phent_setfriction(you,60);
phent_setdamping(you,60,80);

flyvec[0] = 1;
flyvec[1] = 0;
flyvec[2] = 0;
vec_rotate(flyvec[0],camera.pan);

vec_scale(flyvec[0],300000);

phent_addcentralforce(you,flyvec[0]);

wait(-0.2);
}
wait(1);
}
}


Player script:




function camera_move()
{
while(player)
{
camera.pan += 0.5 * ang(player.pan - camera.pan);

vec_set(camera.x,player.x);
camera.z += 60; ///+ sin(total_ticks * 10);

mouse_mode = 0;


wait(1);
}
}



Action player_move()
{
var reldist[3];
var absdist[3];
var input_vec[3];
var Vz = 0;
var jump_able = 1;

my.invisible = on;

player = me;
camera_move();

while(me)
{


vec_set(reldist.x,nullvector);


input_vec.x = (key_w - key_s) * time * 30;
input_vec.y = (key_d - key_a) * time * -18;

my.pan -= 30 * mouse_force.x * time;
camera.pan = my.pan;
camera.tilt = min(max(ang(camera.tilt + 30 * mouse_force.y * time),-60),60);
Vz += (Vz == 0) * 100 * key_space * jump_able;

if(Vz > 0)
{
jump_able = 0;
}
Vz -= (Vz > 0);


c_move(me,input_vec,nullvector,GLIDE);
c_move(me,nullvector,vector(0,0,(Vz - 35) * time),0);
if(trace_hit)
{
jump_able = 1;
}


wait(1);
}
}
Posted By: Volund

Re: Why does it not fly? PLEASE HELP - 08/22/08 02:36

I do an include player and include weapon and include camera in the main.c so they are all seperated and easily transfered to each game. Then in the weapon file i think you could use a c_trace to have the arrow go to your target, maybe event_shoot from the wiki
Also there are tutorials in AUM for each weapon type with examples.
Posted By: CD_saber

Re: Why does it not fly? PLEASE HELP - 08/22/08 10:14

Ok, thanks, but that cannot be the problem... without a camera script, it works just fine!
Posted By: Volund

Re: Why does it not fly? PLEASE HELP - 08/22/08 22:13

Well, so what your saying is that the player part works fine until you add this:


Code:
 function Phy_debug_throw() {
     var flyvec[3];
     vec_set(earthgravity, vector(0,0, -386));
     
          while(1) {
                  
               if(mouse_left) {
     	            you = ent_create("pfeil.mdl",camera.pos,NULL);
     	            c_setminmax(you); 
     	            vec_set(you.pan,camera.pan); 
    	            ph_setgravity(earthgravity);
     	            phent_settype(you,PH_RIGID,PH_BOX);
     	            phent_setmass(you,2,PH_BOX);
     	            phent_setelasticity(you,5,100);
     	            phent_setfriction(you,60);
     	            phent_setdamping(you,60,80);
     	            flyvec[0] = 1;
     	            flyvec[1] = 0;
     	            flyvec[2] = 0;
     	            vec_rotate(flyvec[0],camera.pan);
     	            vec_scale(flyvec[0],300000);
     	            phent_addcentralforce(you,flyvec[0]);
     	            wait(-0.2);
     	       } //END IF 
          } //END WHILE
     } //END FUNCTION 


But this works just fine by itself:

Code:
 function camera_move(){
     
     while(player){
     
          camera.pan += 0.5 * ang(player.pan - camera.pan);
          vec_set(camera.x,player.x);
          camera.z += 60; ///+ sin(total_ticks * 10);
          mouse_mode = 0;
          wait(1); 
     } //END WHILE
} //END FUNCTION

Action player_move(){
     var reldist[3];
     var absdist[3];
     var input_vec[3];
     var Vz = 0;
     var jump_able = 1;
     my.invisible = on;
     player = me;
     camera_move();
     
          while(me){
               vec_set(reldist.x,nullvector);
               input_vec.x = (key_w - key_s) * time * 30;
               input_vec.y = (key_d - key_a) * time * -18;
               my.pan -= 30 * mouse_force.x * time;
               camera.pan = my.pan;
               camera.tilt = min(max(ang(camera.tilt + 30 * mouse_force.y * time),-60),60);
               Vz += (Vz == 0) * 100 * key_space * jump_able;

                    if(Vz > 0){
                         jump_able = 0;
                    } //END IF
               
               Vz -= (Vz > 0);
               c_move(me,input_vec,nullvector,GLIDE);
               c_move(me,nullvector,vector(0,0,(Vz - 35) * time),0);

                    if(trace_hit){
                         jump_able = 1;
                    } //END IF
         
               wait(1);
          } //END WHILE 
     } //END ACTION 


Posted By: CD_saber

Re: Why does it not fly? PLEASE HELP - 08/23/08 08:27

The player script ALWAYS works fine, with AND without the throwing-code. The point is that the throwing code just doesn't work with the player code. When i just put the throwing code inside my script, and do not attach an action to the player (so that I use that default camera, after pressing "0") it works just fine...
Iam not able to understand why... with the player oode attached the arrow IS created but just stands still in the air (passable for some reason...). Is it possible that the WHILE-loop does not work for some reason?
© 2024 lite-C Forums