Game Development Community

Questions about TGB possibilities.

by Collin Burton · in Torque Game Builder · 04/30/2009 (11:03 am) · 6 replies

I'm still holding off purchasing TGB while I go through as many tutorials as I can. However my time is running out and without access to all of the forums I don't know the full potential of TGB.

Without access to the source code (I lack the funds and will be starting with a basic Indie license)...

... is it possible to set a pivot point on a sprite that isn't in the center? Not all objects rotate around their center. For example a tractor-trailer would pivot on the back wheels, not in the center.

... can you set a specific point on a sprite to be the top/front, or does it default to the uppermost point of the sprite?

... can you set a sprite to change appearance each time it's hit by another object? For example a brick breaking apart a bit more each time it's hit by a ball.

... can you set a point of gravity so that all objects that have physics enabled fall toward it, rather than just to the bottom of the screen? For example, have a planet on the screen with gravity set to its center so that everything else falls toward it, or moves along its surface. If so...

... can you set multiple gravity points of varying strength? For example, say I've set a platform on the bottom of the screen with 1G gravity and placed several smaller objects on it. I then have a free-moving object that is controlled by the player with 2G of gravity at its center that the player uses to attract those smaller objects to it when it gets close enough to cancel out the platform's gravity.

That's all I can think of right now. Thank you for any help you can give.

About the author

A gamer since I was old enough to fathom the rules and drawing since I could hold a crayon. For years I've wanted to make games of my own. Now I'm finally doing something about it. You can see my work at my website: www.collinburtondesign.com


#1
05/01/2009 (1:20 am)
I'm only a novice with the TGB, so I'm hesitant to give too much advice. I brought my license years ago, but only just started doing any serious development with it. I'm pretty sure everything you want to do is possible using either the TGB editor or TorqueScript.

I only purchased the basic license - without source code - and haven't run into anything I would actually need the source code for.

I would consider purchasing Torsion also, to make your life a little easier.
#2
05/01/2009 (2:47 am)
Quote:... is it possible to set a pivot point on a sprite that isn't in the center? Not all objects rotate around their center. For example a tractor-trailer would pivot on the back wheels, not in the center.

I believe so, but someone correct me if I'm wrong.

Quote:... can you set a specific point on a sprite to be the top/front, or does it default to the uppermost point of the sprite?

A sprite does not really have a top or front, it just has a position, a size, and a rotation. The global axis in torque is -x left -y up, so any object's rotation means its local space will be that, but rotated. If you need a rotation of zero to correspond with a particular facing, then you can rotate the source art.

Quote:... can you set a sprite to change appearance each time it's hit by another object? For example a brick breaking apart a bit more each time it's hit by a ball.

Definitely, very easily.

Quote:... can you set a point of gravity so that all objects that have physics enabled fall toward it, rather than just to the bottom of the screen? For example, have a planet on the screen with gravity set to its center so that everything else falls toward it, or moves along its surface. If so...

This is not a feature of the stock engine or anything, but sounds very doable in script.

Quote:... can you set multiple gravity points of varying strength? For example, say I've set a platform on the bottom of the screen with 1G gravity and placed several smaller objects on it. I then have a free-moving object that is controlled by the player with 2G of gravity at its center that the player uses to attract those smaller objects to it when it gets close enough to cancel out the platform's gravity.

TGB does not really have a concept of objects or zones that attract/repel others or apply forces. That said, it sounds pretty straightforward to implement everything you described using just scripting.

There are callbacks for doing whatever calculations per object per frame you want, and methods for calculating distance, sweep/collision testing, and applying forces back into objects.

Granted there is a limit to how much of this per frame work you can really afford to do in script, particularly if you happen to be targeting the iphone.
#3
05/01/2009 (6:11 am)
TGB DOES have a concept of just plain zones, though - triggers. Use a trigger's onEnter() method to do funky stuff like changing gravity on the sprite entering, opening remote doors or removing/adding objects to the world.

Changing gravity could be as simple as changing speed in one direction on entering some trigger, and setting it to zero when reaching an object you're moving towards. This could work in a static world, but actual gravity in a dynamic world would need a little source modification, maybe.

You're best off treating the engine as a reactive engine (no onUpdate events) if porting to the iPhone, but some tweaking can allow you to use simple calls at intervals.

Maybe somebody should look into porting Chipmunk Physics, because it's rather lightweight and great for 2D :)
#4
05/01/2009 (7:07 am)
About gravity:
You can attach a constant force to every object. If it is gravity, you just add a little in the Y direction (downscreen).

Gravity toward an onscreen point is a bit more complicated. You'll have to calculate the direction toward the source of gravity and update the constant force in that direction, probably every frame.

For multiple planets, you'll have to make that calculation for all the sources of gravity and add the resulting vectors.

TGB has no sense of an object being a source of gravity. The above would have to be accomplished with a couple lines of code in the update callback for each class of item observing gravity.

TGB's behaviors are great though. These could all be done once in a behavior and the behavior added to each object. Maybe two behaviors: MakesGravity and AffectedByGravity, or something like that.
#5
05/01/2009 (8:36 am)
Thank you all for your responses. That's all good to hear.

@ Samuel: I would love to get Torsion, however I'm developing on a Mac and to the best of my knowledge there isn't a Mac version.

@ James re. rotation: Last night I found a way to do what I needed to do. I wanted one object watch another object with an eye sprite as they both bounced around the screen. By placing the spot of the eye at the top of the eye sprite, then attaching it to a body and using the "Face Object" behavior on the eye it worked exactly the way I wanted.

I won't be developing for the iPhone any time soon since I'll need a license to iTGB and the source for TGB. For now I just want to get a few ideas up and running on the Mac and Windows PCs.

Again, thanks for the encouraging responses.
#6
05/01/2009 (8:38 am)
Annnnnd I was logged in on my son's account.