Strobosaur
Member
Sorry if the answer has already been posted, i've looked around but haven't found any good solutions.
It's a classic case of a projectile traveling too fast to collide with the intended target. I do have a script in place to check for a line collision every step, and it works EXCEPT in the first step after the bullet is created. Here's some code:
It works fine except when the target object is within one length of the bullets speed from the shooter. I've tried a script that instead of checking one length of speed forward checks from one length of speed backwards and up to the current position, which worked but displays the bullet sprite past the collision point for one frame which looks bad. I've tried creating the bullet at the center of the shooting object instead of the tip of the weapon, but same problem... Tried running the line script in the create event of the bullet, or in the shooters 'with instance_create' block for the bullet, but no luck.
Kind of feels like i've missed something obvious here but for the past few days i still haven't been able to figure it out so i now humbly place myself at your mercy Anyone have any ideas?
If there are any other pieces of code that could be of interest just let me know.
Thanks!
It's a classic case of a projectile traveling too fast to collide with the intended target. I do have a script in place to check for a line collision every step, and it works EXCEPT in the first step after the bullet is created. Here's some code:
argument0 is a parent object for solid objects which is what the bullet should hit, shooter is the id of the instance that fired the bullet (which should of course, not be hit).Bullet Step event runs the following script:
var inst = collision_line(x, y, x + lengthdir_x(speed, direction), y + lengthdir_y(speed, direction), argument0, false, false);
var incr = 0;
if (inst != noone) && (inst != shooter)
{
while (!place_meeting(x, y, inst)) && (incr <= speed)
{
x += lengthdir_x(1, direction);
y += lengthdir_y(1, direction);
incr++;
}
}
It works fine except when the target object is within one length of the bullets speed from the shooter. I've tried a script that instead of checking one length of speed forward checks from one length of speed backwards and up to the current position, which worked but displays the bullet sprite past the collision point for one frame which looks bad. I've tried creating the bullet at the center of the shooting object instead of the tip of the weapon, but same problem... Tried running the line script in the create event of the bullet, or in the shooters 'with instance_create' block for the bullet, but no luck.
Kind of feels like i've missed something obvious here but for the past few days i still haven't been able to figure it out so i now humbly place myself at your mercy Anyone have any ideas?
If there are any other pieces of code that could be of interest just let me know.
Thanks!