Legacy GM Physics based recoil?

XirmiX

Member
I've been trying to set up a recoil for when I shoot a projectile for my game. The game is physics based and currently the projectile, after being spawned in will trigger an alarm, which will occur after 1 frame upon it being spawned. Within the alarm is the following code:
Code:
with(obj_hull)
{
    var recoil = phy_mass * acceleration;
    physics_apply_local_force(obj_turret.image_angle,0,-recoil,0)
}
This doesn't exactly do what I expect it to do. Remember this is a tank that is controlled. The obj_turret is the weapon and the obj_hull is the base part (this is a top-down shooter I'm working on btw). I'm expecting to have the projectile, when spawned (so, I guess the alarm doesn't really have much of a purpose) to push the hull a little bit in the opposite direction the projectile is travelling or in the opposite image_angle/direction of the turret. With what I've done so far, the hull moves, but always in the opposite direction IT is facing and not in the opposite direction to which the TURRET is facing.
 

XirmiX

Member
So, I realize that one thing I've been doing wrong is mixing up recoil with impact force (recoil being the force that acts upon the object that is shot from when you shoot a projectile and impact force being the force that acts upon an object when a projectile hits it). Still, trying some code, especially with the fact that this involves SohCahToa, which I'm not good at all, it all came to these two pieces of code within alarms that I just can't get right.

Impact force code:
Code:
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) * 5;
        tipy = y + -dsin(projectile_angle) * 5;
        physics_apply_local_impulse(projectile_angle,0,-tipx,-tipy)
    }
    instance_destroy();
}
else
{
    alarm[1] = 1;
}
Recoil code:
Code:
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)
}
And I think I lack a bit in understanding the components of impulse and force... I know what they do, I am just not sure sometimes what each component of x and y is for. Agh, I feel tired... Some help in this, if anyone can offer would be really appreciated.
 

XirmiX

Member
Anybody? Currently the recoil applies no force for whatever reason and the impact force pushes the hull diagonally south east of where it is standing (also locally; based on the angle the hull is turned) and not in the direction that the projectile was travelling just before colliding with the hull.
 
Top