Game Development Community

Projecting Rays

by Daniel Novatnak · in Torque Game Builder · 02/03/2008 (8:24 pm) · 3 replies

I'm trying to get movement for a game and I want to use projected rays for obstacle avoidance.
I searched but nothing of relevance was found, so, is there some sort of ray projecting function in Game Builder, or do I need to make an object, mount it to my moving object and use that instead?

#1
02/03/2008 (10:45 pm)
I think you should have a look at "pickLine" or other "pick" functions. They will return a list of objects which intersect the line or shape that you choose.
#2
02/05/2008 (11:53 pm)
This is somewhat related but, please tell me why this code doesn't work:

function initializeProject()
{
   // Load up the in game gui.
   exec("~/gui/mainScreen.gui");
	

   // Exec game scripts.
   exec("./gameScripts/game.cs");
	exec("./gameScripts/gameLogic.cs");
	exec("./gameScripts/playerShip.cs");
	
	echo("Start");
   // This is where the game starts. Right now, we are just starting the first level. You will
   // want to expand this to load up a splash screen followed by a main menu depending on the
   // specific needs of your game. Most likely, a menu button will start the actual game, which
   // is where startGame should be called from.
   startGame( expandFilename($Game::DefaultScene) );
}

The gameLogic.cs file:

function gameLogic::onLevelLoaded(%this, %scenegraph)
{

	echo("------->Start 2");
	$player1 = new ScriptObject(playerShip){};
	$player1.init(%scenegraph);
	
	echo("End");
	
}



And playerShip.cs file
function playerShip::init(%this, %scene){
	echo("------->Start 3");
	%this.angularSpeed = 25;
	%this.linearSpeed = 35;
	
	%this.myImage = new t2dStaticSprite()
	{
  		    scenegraph = %scene;
  			
	};
	%this.myImage.setImageMap(playerImageMap);
	%this.myImage.layer = 0;
	%this.myImage.setPosition(0,0);
	
	%this.myImage.visible = true;
	/*
	moveMap.bindCmd(keyboard, "up", "playerShipUp(%this);", "playerShipUpStop(%this);");
    moveMap.bindCmd(keyboard, "down", "playerShipDown(%this);", "playerShipDownStop(%this);");
    moveMap.bindCmd(keyboard, "left", "playerShipLeft(%this);", "playerShipLeftStop(%this);");
    moveMap.bindCmd(keyboard, "right", "playerShipRight(%this);", "playerShipRightStop(%this);");*/
	
}


All I want this to do is make a ship appear in the scene, is that so hard?? Console reports no errors and only echos "Start"
#3
02/06/2008 (12:34 am)
I think you are putting the exec() functions in the wrong location. I don't think you should mess around with the "main.cs" file in the game directory. You should initialise your scripts from the "game/gameScripts/game.cs" file in the function "startGame()". This is the *typical* point for you to load your game scripts.

Secondly, I don't think that the "onLevelLoaded()" function is being called because the class "gameLogic" is nonexistent. In order for this function to be called an object needs to be loaded into the scene when the level is loaded.

I would recommend that you do something like:

function startGame(%level)
{
   ...
   exec("./gameScripts/playerShip.cs");
   $player1 = new ScriptObject(playerShip);
   $player1.init(sceneWindow2d.getScenegraph());
   ...
}

In general, callback functions are only called when that condition is met. If you searched for the "onLevelLoaded()" callback, you will notice it is a method belonging to t2dSceneObjects. For future reference, you should check out the documentation for the functions you are trying to use. You did well in your attempt to see which functions were being called with the echo functions, but when something doesn't work without any errors, check your logic.