Game Development Community

[resolved] onCollision or lack there of creates object

by rennie moffat · in Torque Game Builder · 02/20/2010 (6:01 pm) · 4 replies

hi, i am trying to create a new object from classA when it is not in contact with object from classB.


I have a onCollision call for classA,

if(%dstObject !$= "classB")
%srcObject.makeNewAObject();


the thing is the computer justs generates a new star after new star after new star so it is just making more and more and more, not cool. I have been struggling with this problem for a while. I have tried juggling multiple objects, but have decided I just need to create a new object when the previous has been removed.


Please, if anyone has a moment, please help me solve this problem as it is crucial to my game. I am relatively new to programming so please be kind.
thanks,
Ren



My code as of now
function starsStarClass::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
	if(%dstObject.class $= "starClass")
	%srcObject.mountStar();
	
///this is the call of concern
	if(%dstObject.class !$= "starGeneratorClass")
	%srcObject.createNewStar();
}

function starsStarClass::mountStar(%this)
{
	%this.mount($star, 1, 1, 0, true, true, true);
	%this.setCollisionActive(false, false);
}

function starsStarClass::createNewStar(%this)
{
/// here i create new object, but I think the computer sees the original starsStar as the only one that counts for colliding with the object
	%this.starsStar = new t2dStaticSprite()
	{
		scenegraph = %this.scenegraph;
		class = starsStarClass;
	};
	
	%this.loadNewStar();
}

function starsStarClass::loadNewStar(%this)
{
	%this.setImageMap(starsStarImageMap, 0);
	%this.setPosition(30, -20);
	%this.setSize(6, 4);
	%this.setLayer(4);
	%this.setCollisionActive(true, true);
}


it was my thought that when a new starsStar is loaded, and is in collision with the starGenerator object, that it will count for a collision and thus, stop generating new ones. I thought it would only create one!!!!


:?


About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
02/20/2010 (6:52 pm)
Your "onCollision" function is obviously expecting to collide with many different things. I can tell because you are checking for both "starClass" and "starGeneratorClass".

The easiest way to test this is to add the following to the "onCollision":
echo( "%dstObject.class = " @ %dstObject.class );
and check the console.

Every time that this class collides with something else you'll generate a star. This could be the floor, the "starClass", or anything else that isn't "starGeneratorClass", and you'll generate a star.

As a general rule, I don't rely on the physics engine to determine what my game can and cannot do. I keep a separate class that determines what my game can and cannot do. The physics engine can modify that class. The physics engine might check that class to determine how the physics should react. But I never use the physics engine to determine what my game should be doing.
#2
02/20/2010 (6:55 pm)
ok,
well I was thinking of using an onLeave call, but can i use that if my object is not a t2dTrigger?

I have heard there are issues with the triggers.


#3
02/20/2010 (7:01 pm)
I just ran it with the echo call.

it reads that the starClass is colliding with it. This is good.

The trick is that well, the same old same old.
Like I say I have tried many approaches to this and I want to get it nailed. I know im nearing it, but not yet there.

:Hmmph.




#4
02/21/2010 (12:07 am)
I have done this, i have stopped using the onCollision cal, and replaced it with if a starsStar is mounted.. however it seems I can not get the new starsStar, when generated to recognize that it is not the other starsStar. What I mean is that when the new one is generated, it leaps from the load position to the mount position on the player, even if he is on the other side of the screen. This is not good.

I need to figure out how to get that new star to not leap to the mount of the player. I have tried quite a few things, having a variable and if false nothing happens, turning collisions off, so there is no way the new starsStar will think it is colliding with the player, as the mounted object might.

this is some of my code.
if you can help me please do.
thanks!

function starsStarClass::mountStar(%this, %object)
{
	%this.object.mount($star, 1, 1, 0, true, true, true);
	%this.object.setCollisionActive(false, false);
	%this.schedule(3000, createNewStar); 
	$starMounted == 1;
}

function starsStarClass::createNewStar(%this)
{
	%this.starsStar = new t2dStaticSprite()
	{
		scenegraph = %this.scenegraph;
		class = starsStarClass;
	};
	
	%this.loadNewStar();
}


function starsStarClass::loadNewStar(%this)
{
	if($starMounted == 0)
	return;
	
	%this.setImageMap(starsStarImageMap, 0);
	%this.setPosition(30, -20);
	%this.setSize(6, 4);
	%this.setLayer(4);
///i even tried to set collisions both false, but nothing.
	%this.setCollisionActive(true, true);
}