X
XirmiX
Guest
I belive I've made a thread about this before, although I did not get any help there really and it seems like it was a tough nut to really comprehend. I'm talking in terms of recoil and impact force which get applied by shot projectiles at a target or basically an enemy or yourself. Obviously, this is taking physics into mind.
My projectile object, currently has Create event setting off two alarms; alarm 1 and alarm 2. Alarm 1 is activated after 3 frames (reason being that the gun/turret you're shooting from is attached to a hull and so when you shoot your projectile from the turret, the turret and the spawn point of the projectile on the turret might overlap the hull that the turret is sitting on, so having a delay before any impact force and collisions with the hull happen is necessary) and Alarm 2 gets activated as soon as the projectile is created (because this alarm is supposed to apply recoil). This is the code I have for the according alarms as it stands:
Alarm 1:
Alarm 2:
The problem for me is that the stuff in the first alarm, upon impact with a projectile instance make the hull move to its down-left or south-west a bit instead of in the direction that the projectile hit it from and the recoil does absolutely nothing to the hull (it's as if the force isn't even applied). I know what I'm doing wrong for the first one, and it's in terms of the whole "projectile_angle = obj_ricochet_projectile.direction;" because the projectile is physics based, so it has an impact force moving it forward and not direction, however it would not make sense by GML logic to make the code be something like "projectile_angle = obj_ricochet_projectile.local_force;" because, well, for one local force isn't something defined, but something that can only be applied (the projectile detaches on walls, btw, so this is why you could hit your own hull for the tank, which is what I'm trying to make happen atm). So, question is, how could I do the first alarm code so that it works as intended (impact force) and why does recoil not get applied for the hull and how could I apply it?
P.S Ricochet splat is basically this neat little thing I put into the game that spawns in when the projectile hits a wall or something, which just makes it look pretty
My projectile object, currently has Create event setting off two alarms; alarm 1 and alarm 2. Alarm 1 is activated after 3 frames (reason being that the gun/turret you're shooting from is attached to a hull and so when you shoot your projectile from the turret, the turret and the spawn point of the projectile on the turret might overlap the hull that the turret is sitting on, so having a delay before any impact force and collisions with the hull happen is necessary) and Alarm 2 gets activated as soon as the projectile is created (because this alarm is supposed to apply recoil). This is the code I have for the according alarms as it stands:
Alarm 1:
Code:
//Applying impact force
if place_meeting(x,y,obj_hull)
{
instance_create(x,y,obj_ricochet_splat)
//motion_add(phy_rotation,phy_mass)
//move_bounce_solid(true);
with(obj_hull)
{
var tipx, tipy;
projectile_angle = obj_ricochet_projectile.direction;
tipx = x + dcos(projectile_angle) * 0.1;
tipy = y + -dsin(projectile_angle) * 0.1;
physics_apply_local_impulse(projectile_angle,0,-tipx,-tipy)
}
instance_destroy();
}
else
{
alarm[1] = 1;
}
Alarm 2:
Code:
//Applying recoil
with(obj_hull)
{
var recoil = phy_mass * acceleration;
var tipx, tipy;
turretAng = obj_turret.image_angle;
tipx = x + dcos(turretAng) * recoil;
tipy = y + -dsin(turretAng) * recoil;
physics_apply_local_force(-96,0,-tipx,-tipy)
}
P.S Ricochet splat is basically this neat little thing I put into the game that spawns in when the projectile hits a wall or something, which just makes it look pretty