I am having a problem with this function. It creates a projectile that is supposed to appear aligned to the player. It appears aligned only sometimes. I don't understand it because I have made similar functions in the past with no problems, it should be simple right?
Code:
//use action
function init_use_action()
{
//locals
var init_spell;
init_spell = off;
//terminate if already in progress
if(my.current_state == _state_use){return;}
//setup this state
my.current_state = _state_use;
my.anim_new_scene = my.scene_use;
//loop while state is valid
while(my.anim_dist < 100)
{
//cancel still count
my.still_count = 0;
//execute only if player is aligned to camera
if(my.pan <= camera.pan + 10 && my.pan >= camera.pan - 10)
{
//wait for animation blending
while(my.anim_dist == -1){wait(1);}
//handle creation of spell
if(my.anim_dist > 10 && init_spell == off)
{
init_spell = on;
//create spell
you = ent_create("temp.mdl",my.x,mis_generic);
vec_set(you.pan,my.pan);
}
//animate for current state
my.anim_dist += (8 * time_step);
ent_animate(me,my.anim_new_scene,my.anim_dist,anm_cycle);
//while using, rotate with mouse force
my.pan -= (mouse_force.x * 5) * time_step;
}
//align to camera
pl_rotate(camera.pan,20);
wait(1);
}
//update states
my.scene_idle = "idle";
my.last_state = my.current_state;
wait(1);
init_idle_action();
}
Here is the function of the created entity and its event function.
Code:
//generic spell projectile event
function event_mis_generic()
{
//on impact with entity
if(event_type == event_entity){my.hp = 0;}
//on impact with block
if(event_type == event_block){my.hp = 0;}
}
Code:
//generic spell projectile
function mis_generic()
{
//setup
setup_bb();
my.roll = random(360);
my.passable = on;
// my.invisible = on;
my.hp = 1;
//setup events
my.enable_entity = on;
my.enable_block = on;
my.event = event_mis_generic;
//while in effect
while(my.hp > 0)
{
//make unpassable if 'old' enough
my.hp += (1 * time_step);
if(my.hp > 10){my.passable = off;}
//move me
c_move(me,vector(30,0,0),nullvector,ignore_passable|use_box);
//roll
my.roll += (15 * time_step);
wait(1);
}
ent_remove(me);
return;
}
Things that I have already tested:
The player's origin is centered, no problems there. The "temp.mdl" is a simple diamond shape and its origin is in the center as well.
For $h!ts and giggles, I commented out the c_move and make unpassable part to see if it appears a befunkled alignment and it is aligned to the center correctly so I can't figure it is a problem with anything else.