Game Development Community

Wierd behavior (possible bug) and no collision detection

by Derrick Simpson · in Torque X 2D · 02/13/2007 (5:03 pm) · 7 replies

Just to play around with Torque X , I created a new GSE "StarterGame" project. I opened the project and level with TGBX to edit it.
- I drew a collision poly around the already existing GG logo
- I added a second GG logo, and drew a collision poly around it as well.

Without doing anything else, collision detection worked.

Now, I created a second version of the Starter Game project. I created a few png files (for the ground) , created materials from them, and added them to the level. I drew collision polygons around each of them (three chunks).

Next, I imported the 2 pngs which are my main player. A torso, and the legs.

- I mounted the legs onto the torso.
- I drew collision polys around both objects.
- I removed the MovementComponent from the GG logo.
- I added the MovementComponent to the Leg object.

Now, when I start the game, I am expecting to be able to move the guy with the controller. It works... However..., not only does the collision detection not work, but there's a duplicate of the torso image, that doesn't follow the player around. The torso, and legs move around as expected... just as the GG logo did, but a copy of the torso stays put.

About the collision detection not working... By default, when you drag a material onto the level, it creates a component which has both the T2DCollisionComponent, and T2DPhysicsComponent.

Also, under the "Scene Object" section, collision is enabled...

So, Instead of making MovementComponent extend a TorqueComponent, I extend the T2DCollisionComponent, and attempt to override the OnCollision method. However, I get the following error

'StarterGame.MovementComponent.OnCollision()': cannot override because 'GarageGames.Torque.T2D.T2DCollisionComponent.OnCollision' is not a function


Am I using the T2DCollisionComponent wrong ? Am I doing something wrong in TGBX ? Any help will be greatly appreciated...

- Derrick

#1
02/13/2007 (7:32 pm)
I think that I am kind of understanding it now. Although, I still didn't get it to work. (yet).

If you add the T2DCollisionComponent to your object in TGBX, you'll get an OnCollision callback. I am looking at the CombustibleComponent from Tank Buster, and it does not extend the T2DCollisionComponent, yet it has an OnCollision method. I thought, from reading the "Getting Started" html page, that I should be extending the T2DCollisionComponent, and overriding the OnCollision method. I am still a little confused about what's what, I suppose.
#2
02/13/2007 (7:57 pm)
@Derrick - The OnCollision property in T2DCollisionComponent is a delegate. You assign the method that you want to get called into the delegate. You can put any method you want (that matches the signature of the delegate) into OnCollision in T2DCollisionComponent, so you can (and probably should) define it somewhere else, not necessarily in something that inherits from T2DCollisionComponent. And the method can be named anything you want -- there's nothing magical about "MyClass.OnCollision" in TorqueX. Does that make sense?

In the TorqueX programming model, you usually think of an "object" as an aggregation of particular components. "Extending" a component in the classical object-oriented hierarchical inheritance way of thinking is a bit unusual. In your case, you would want your object to have both the collision component and the movement component because you want it to have both "colliding" and "moving" functionality. Trying to merge them together into some kind of super-component is sort of fighting the programming model.
#3
02/14/2007 (10:35 am)
Dan covered the second question very well, so I'll address the first.

My guess is that you have both the template for your player and the spawnObject for the player in the same location. When you run the game, you spawn the player and it moves, but you are still seeing the original object template in the spawning location.

Try moving your template object off your screen, and only leave the spawn object where you want your player to spawn and see if that removes the effect.

FYI, having template objects "in scene" is a workflow issues that is being worked on....the team will probably create a "special place" in the editor for placing template objects so they aren't directly in the scene, but the details aren't finalized yet.
#4
02/14/2007 (11:02 am)
Ooer, great Idea Stephen. A seperate area for template objects would be fantastic! That made me think of another feature request too: an option on a material to create a spawnobject from it.




www.linkedin.com/img/webpromo/btn_viewmy_160x25.gif

www.mmogamedev.info/images/imgdc_ad1.gif
#5
02/20/2007 (3:32 pm)
Thanks for the replies. I forgot to check the little "Notify Me" checkbox, yet thought that I would get emailed when someone replied. So, no email, and I didn't think anyone was responding. Sorry... It's checked now though. heh

Dan,
I see now... I do understand delegates. Thanks for the explanation.

Stepehen,
I'm not creating a template. I'm doing it the exact same way that the Starter Game example uses. In which the logo is being moved around, etc. I am not even sure what a "SpawnObject" is. So I'm pretty sure I'm not using one. :-/


Also, one of my main points was that there is no collision happening. Regardless of whether I handle it in an OnCollision method, shouldn't it still be happening? I'm doing everything I did with the two GG logos, just with different materials.


Also, does the ComponentSpecs.ed.cs basically bind the TGBX component to a C# object ?
#6
02/20/2007 (3:59 pm)
Quote:Also, does the ComponentSpecs.ed.cs basically bind the TGBX component to a C# object ?
Basically, yes. Later versions of Torque X have replaced it with a different system that auto-magically achieves similar functionality, so you don't need to bother manually editing the file, or worry about keeping it in synch with changes you might make to your C# code.
#7
02/20/2007 (4:01 pm)
Actually, let me clarify that a bit to make sure there's no confusion. "Components" are not a TGBX specific thing. "Components" are a Torque X thing, and TGBX has support for them, implemented via the ComponentSpec.ed.cs in the open-beta version, and with a different system in later versions.