Need Help Calling a Function / Help with multiple Actions?

Posted By: MattyTheG

Need Help Calling a Function / Help with multiple Actions? - 08/06/08 00:16

Hello everyone, I am working on this game where you shoot an airplane with a missile. Yea its pretty generic right now but I'm working on it haha. Let me put in my code before I go any further.

#include <acknex.h>
#include <default.c>

var earthgravity[3]= 0,0, -386;
var launch_angle= 45;

function missile_flying()
{
while (1)
{
my.roll = my.roll + 3;
wait(1);
}
}

function main()
{
level_load ("PhysicsTest.wmb");
wait (2);
while (1)
{
launch_angle += key_cuu * .05;
launch_angle -= key_cud * .05;
wait(1);
}
}

action ball_drop()
{
while (key_space == 0) {wait (1);}
phent_settype(my, PH_Rigid, PH_box);
phent_setmass (my, 2, PH_box);
ph_setgravity (earthgravity);
phent_addvelcentral(my, vector(0, -472 * cos(launch_angle) , 472 * sin(launch_angle) ) );
function missile_flying();
wait(1);
}

action plane_fly()
{
while (key_space == 0) {wait (1);}
phent_settype(my, PH_Rigid, PH_Box);
phent_addvelcentral (my, vector(0, -472*cos(45), 0) );

}

Ok I have the code set up so that while the user is not pressing space, the action waits. Then when the spacebar is pressed the missile launches, as well as the plane.

The problem is that I want the missile to rotate, but if I put the my.roll = my.roll + 3; into the action ball_drop, it does not work. So I made it into a function and tried to call it when the missile launches.

I get an error saying empty function. I also want to work around the tilt modifier and what not, but it seems to be that I either have an action where the missile rolls, or one where it launches and can't get them to work simultaneously.
Posted By: MrGuest

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 00:21

in
Code:
action ball_drop()
{
while (key_space == 0) {wait (1);}
phent_settype(my, PH_Rigid, PH_box);
phent_setmass (my, 2, PH_box);
ph_setgravity (earthgravity);
phent_addvelcentral(my, vector(0, -472 * cos(launch_angle) , 472 * sin(launch_angle) ) );
function missile_flying();
wait(1);
}


delete the
Code:
function missile_flying();


and replace it with just
Code:
missile_flying();


Hope this helps!
Posted By: MattyTheG

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 00:31

Well that fixed the error, I no longer have an empty function, so thank you for that. The missile launches now, which is known as ball_drop because I forgot to change the name haha.

When I press space now, it launches like it should, I get no errors, but my missile still doesn't roll, any suggestions?
Posted By: MrGuest

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 00:45

unfortunately... the bits in game studio i use

aren't A7
aren't physics
and aren't planes and missiles :P

couple of ideas though,

when you call a new function you should really pass things through it in the parameters to make sure it's still calling the right entity, i'm not sure if A7 does/doesn't return errors for this,

Code:
action ball_drop()
{
while (key_space == 0) {wait (1);}
phent_settype(my, PH_Rigid, PH_box);
phent_setmass (my, 2, PH_box);
ph_setgravity (earthgravity);
phent_addvelcentral(my, vector(0, -472 * cos(launch_angle) , 472 * sin(launch_angle) ) );
missile_flying(me);
wait(1);
}


Code:
function missile_flying(localEnt)
{
me = localEnt;
while (1)
{
my.roll = my.roll + 3;
wait(1);
}
}

try that?

2ndly, i don't know if playing with physics prevents you doing any other object manipulation? maybe someone else could answer that

3rdly, if your missile is symetrical all the way around, then you wouldn't necessarily see if .roll is working? try it's .tilt see if that makes it obvious

just some suggestions but doubt they matter? smile
Posted By: cro_games

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 00:56

Bone animation..
Add bone in the center of the model,name it "bone1",attach whole model to the bone and use this code:

ent_bonerotate(my,"bone1",vector(0,0,5));
Posted By: MattyTheG

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 01:01

Yikes, now I can't even get the vertices to attach to a model. Mr Guest your suggestions did not help, but thank you very much for trying.

Ok I have my model, I selected bones mode, clicked create bone, and placed one in the middle of my missile. Next I selected vertices mode, selected all the vertices, and clicked attach, but none of them attached, they all stayed yellow.

Should I post this in MED help forum now?

BTW, should that ent_bonerotate go in the action right after the ball launches, or my new function that I am calling?

Thanks for the effort guys.
Posted By: cro_games

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 01:15

Send the model and the whole code in "zip/rar" to my e-mail: emu_hunter_1990@hotmail.com..
Posted By: MattyTheG

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 02:00

That works perfectly, thank you very much Cro.
Posted By: cro_games

Re: Need Help Calling a Function / Help with multiple Actions? - 08/06/08 02:02

Np man,np..
Any time..
© 2024 lite-C Forums