Game Development Community

My projectile doesn't arc correctly

by Orion the Hunter · in Torque Game Builder · 08/24/2012 (2:34 pm) · 5 replies

Hi,

I made a new projectile for my platformer. I want to make it be like a bomb that you can throw which arcs up high (about 5 inches) in the sky, but then falls to the ground. Here's what I did:
ProjectileArc    = 100;
but it's really unpredictable. It either shoots downwards, or shoots about forty to sixty degrees upwards, and doesn't seem to be affected by gravity. Here's what I want: s17.postimage.org/8gcru8e9b/good.png
but instead, it flies continuously in one of these directions: (I think it may be bound to the direction the player is facing. If so, manipulating that would be good.)
s9.postimage.org/nsoc4d6r3/bad.pngANY help will be much appreciated. Thanks!

~AJPCEO

#1
08/24/2012 (5:44 pm)
What is the code for the projectile moving and such?
Do you have a constant force pointing down?
How does your gravity work?
How does the projectile arc variable work into it all?
Sorry for all the questions, I have an idea or two on how I would attempt to solve it we need a little more info. :)
#2
08/25/2012 (6:17 am)
Well, I am afraid I don't know the answers to those questions. I use the PSK and I did not make those things. I guess Mr. O'Shea would be a better person to ask. Anyway, I look around to see what I can find concerning those questions.
#3
08/25/2012 (9:12 am)
Here's some old Molotov code I wrote a few years ago. It should give you a good idea of how to do it:
datablock t2dSceneObjectDatablock( MolotovProjectileData : ProjectileBaseData )
{
    Class             = "MolotovProjectile";
    AnimationName     = "redFishAnimation";

    CollisionCallback      = true;
    CollisionDetectionMode = "PLATFORM_CIRCLE";
    CollisionCircleScale   = 0.2;

    Lifetime          = 10.0;
    Size              = "12.000 10.000";
    
    ProjectileDamage  = 12;
};

new ScriptObject( MolotovLauncherAction : ProjectileBaseAction )
{
    ProjectileType   = "t2dAnimatedSprite";
    ProjectileConfig = MolotovProjectileData;
    ProjectileSpeed  = 70;
    ProjectileOffset = 1;
    ProjectileArc    = 0;

    CoolDown         = 500;
    Continuous       = false;

    Burst            = false;
    BurstCount       = 3;
    BurstDelay       = 30;

    //TriggerSound     = RocketLauncherFireSound;
};

//-----------------------------------------------------------------------------

new ScriptObject( MolotovLauncherWeapon : WeaponBase )
{
    // Action
    ActionCount = 1;
    Action[0]   = MolotovLauncherAction;
};

//-----------------------------------------------------------------------------

function MolotovProjectile::onAddToScene( %this )
{
   %this.LinearVelocity.Y = -100;
   %this.setConstantForce( 0 SPC 200, true );
}

function MolotovProjectile::onRemove( %this )
{
    // Create Impact Animation.
    %impactEffect = new t2dAnimatedSprite()
    {
        SceneGraph    = %this.getSceneGraph();
        Class         = "MolotovImpactEffect";
        AnimationName = "SonicPunchImpactAnimation";        
        Position      = %this.Position;
        Size          = "25 25";
    };
    
    // Fetch the Volume for the Effect.
    %volume = $Game::Player.getSoundVolume( %this.Position );
    
    // Play Sound Effect.
    //playSound( "SonicPunchImpactSound", %volume );
    
    %impactEffect.schedule(100,"SpawnMoreFlames",%this.Position.X - 5, %this.Position.Y);
    %impactEffect.schedule(100,"SpawnMoreFlames",%this.Position.X + 5, %this.Position.Y);
    %impactEffect.schedule(150,"SpawnMoreFlames",%this.Position.X - 10, %this.Position.Y);
    %impactEffect.schedule(150,"SpawnMoreFlames",%this.Position.X + 10, %this.Position.Y);
    %impactEffect.schedule(200,"SpawnMoreFlames",%this.Position.X - 15, %this.Position.Y);
    %impactEffect.schedule(200,"SpawnMoreFlames",%this.Position.X + 15, %this.Position.Y);
}

function MolotovImpactEffect::onAddToScene( %this )
{
   %this.DamageValue = 10;
   
   // Make sure this object doesn't collide but still interacts
   %this.setCollisionActive( 0, 1 );
   %this.setCollisionPhysics( 0, 0 );
   
   %this.setCollidesWith( "" );
   %this.schedule(1000,"Update");
   
   %this.Hitbox = new t2dSceneObject()
   {
       ObjectType = "EnemyHitbox";
       ActorType = "Invulnerable";
       Scenegraph = %this.Scenegraph;
       Size = %this.Size;
       Owner = %this;
       CollisionPolyList = %this.CollisionPolyList;
   };
    
   %this.Hitbox.setCollisionActive(1,1);
   %this.Hitbox.setCollisionPhysics(0,0);
   %this.Hitbox.setCollidesWith("PlayerObject");
   %this.Hitbox.mount( %this );
}

function MolotovImpactEffect::SpawnMoreFlames( %this, %x, %y )
{
// Create Impact Animation.
      %impactEffect = new t2dAnimatedSprite()
      {
         SceneGraph    = %this.getSceneGraph();
         Class         = "MolotovImpactEffect";
         AnimationName = "SonicPunchImpactAnimation";        
         Position      = %x SPC %y;
         Size          = "25 25";
      };
    
      // Fetch the Volume for the Effect.
      //%volume = $Game::Player.getSoundVolume( %this.Position );
    
      // Play Sound Effect.
      //playSound( "SonicPunchImpactSound", %volume );
}

function MolotovImpactEffect::onAnimationEnd( %this )
{
   %this.safeDelete();
}
#4
08/25/2012 (3:52 pm)
Thanks! It works GREAT now! Quick question on the subject of weapons: is it possible to make the weapons hurt the actors? I am considering an online game mode where it would be useful.
#5
09/02/2012 (2:19 pm)
There is a takes damage and deals damage behavior you can study to get that working. It should be on the TDN with all the behaviors.