Game Development Community

Earth Gravity - Free Fall Pinball Object Needed

by Will Zettler · in Torque Game Builder · 01/19/2011 (2:09 pm) · 1 replies

Hey all,

Quick question. I have been using TGB since the start off and on. More so now then ever before. Working on a few different versions of pinball-like games, and needed to know how you get the ball to do direct gravity like when you pull the plunger down, it falls with it? What I have is a spacey-like ball that floats and bounces around, but nothing that uses direct gravity to pull it down like on earth. Is there a piece of code that might work? I used everything I could think of on the editor side of tgb. Being a non-programmer don't help either, I try to stay away from the script or code side whenever possible, but that might soon change for these projects. Anyone know anything on how to do this? Everything I try seems to be floaty, and that's not what I'm looking for. Thanks so much in advance for any leads to get this working.

Will
dlstorminc@yahoo.com
Hobby Farm Studios
Indianapolis, IN

About the author

- Ambient sound artist since 2004 - Texture artist since 2001 - Terrain designer since 2006 - Android app design since 2016 - Game design (Sky Fall, A_Clone) 2018


#1
01/19/2011 (11:39 pm)
Building off what we had earlier, you can try something like so:
function Launcher::onLevelLoaded(%this, %scenegraph)
{
   echo("Launcher loaded");  
   
$SG = %scenegraph;   
   
   //setup some params   
   $MIN_HEIGHT = 10;
   $MAX_HEIGHT = 20;
   
   $START_POS_Y = %this.getPositionY();   
   
   $MAX_VELOCITY = -1;   
   
   $MAX_CHARGE = 100;
   $CURRENT_CHARGE = 0;
   $CHARGING = false;

   %this.enableUpdateCallback();
   
   moveMap.bindCmd(keyboard, space, "startCharging();", "releaseBall();");
}

function startCharging()
{
   echo("Starting to charge");     
   $CHARGING = true;
}

function releaseBall()
{
   echo("Relasing ball with charge: " @ $CURRENT_CHARGE); 
   
   $CHARGING = false;
   
   MainLauncher.setHeight($MAX_HEIGHT);
   MainLauncher.setPositionY($START_POS_Y);
   
   MainPinball.setLinearVelocityY($CURRENT_CHARGE * $MAX_VELOCITY);
   MainPinball.atRest = false;
}

function Launcher::onUpdate(%this)
{
   if($CHARGING)
   {
      if($CURRENT_CHARGE < $MAX_CHARGE)
      {
         $CURRENT_CHARGE++;  
         
         MainLauncher.setHeight($MAX_HEIGHT - ($CURRENT_CHARGE / $MAX_CHARGE) * $MIN_HEIGHT);
         MainLauncher.setPositionY($START_POS_Y + $MAX_HEIGHT - %this.getHeight());
         
         echo("Launcher PosY: " @ MainLauncher.getPositionY());
      }
      else
      {
         $CURRENT_CHARGE = $MAX_CHARGE;
      }
      
      echo("Launcher charging: " @ $CURRENT_CHARGE); 
   }
   else
   {
      $CURRENT_CHARGE = 0;
   }
}

function Pinball::onLevelLoaded(%this, %scenegraph)
{
   %this.enableUpdateCallback();
   
   %this.gravity = 0;  /* rate of change of position due to grav*/
   %this.acceleration = 0.05; /* rate  of change of grav*/

   %this.atRest = true;
}

function Pinball::onUpdate(%this)
{
   if(!%this.atRest)/* above ground*/
   {
      %this.gravity = %this.gravity + %this.acceleration; /*increase speed of drop*/
      %this.setPositionY(%this.getPositionY() + %this.gravity); /*apply speed to position*/
   }
   else
   {
      %this.gravity = 0; /*touching the ground has stopped Y movement due to gravity*/
   }
}