M
MegaJim73
Guest
I've been tinkering the hitscan code I made in my previous thread for a shotgun in my FPS but it has a couple of quirks that keep it from functioning as intended:
- When aimed at an enemy, only up to three 'pellets' will hit the enemy and do damage, regardless of how many 'pellets' are fired. Otherwise they make the appropriate number of impacts.
- The spread is tight but not as 'directed' as intended. Is there a better way to calculate the velocity for the 'pellets'? (global.camcos = cos(direction*pi/180) and global.camsin = sin(direction*pi/180) respectively for reference.)
Code:
{
// check whether you can shoot
if (not can_shoot) exit;
can_shoot = false;
// show the animation and play the sound
image_speed = 0.5;
image_index = 0;
sound_play(snd_shtgn);
global.shells-=1;
var xx, yy, ii;
xx = global.camx;
yy = global.camy;
repeat(6)
{
for (i=0; i<256;i+=2)
{
xx += (4+random_range(-1,1))*global.camcos;
yy -= (4+random_range(-1,1))*global.camsin;
if (position_meeting(xx,yy,obj_wall_basic))
{ ///You hit a wall, ricochet.
t=instance_create(xx,yy,obj_ricochet);
t.direction=obj_player.direction;
t.z1=ii.z1*0.75;
break;
}
else
if (position_meeting(xx,yy,obj_monster_basic))
{ ///You hit an enemy, deal damage.
ii = instance_position(xx,yy,obj_monster_basic);
if (ii == noone) continue;
with (ii)
{
mhealth-=1;
hurt=1;
t=instance_create(xx,yy,blood_type);
t.z1=ii.z1*0.75;
break;
}
}
else
if (position_meeting(xx,yy,obj_pillar1))
{ ///You hit a column, ricochet.
ii = instance_position(xx,yy,obj_pillar1);
if (ii == noone) continue;
with (ii)
{
if (indestructible==0)
{
mhealth-=1;
t=instance_create(xx,yy,blood_type);
t.z1=ii.z1*0.75;
};
else
t=instance_create(xx,yy,blood_type);
t.z1=ii.z1*0.75;
break;
}
}
//alert other enemies within radius
with (obj_monster_basic)
{
if ((id != other.id) && collision_circle(global.camx,global.camy,128,id,1,0))
{
with (id) alert=1;
}
}
};
}
}