Torquex1.5 + platformer kit
by Sean Dinwiddie · in Torque X 2D · 03/08/2008 (9:17 am) · 25 replies
I was looking to do a game like Prince of Persia on the XBLA, a 3D, side-scrolling, platformer with no z-axis.
Is there any way to combine the Platformer Starter kit with 3D assets?
Is there any way to combine the Platformer Starter kit with 3D assets?
#2
I was thinking of doing the latter considering the Platformer Kit was coded with 2D in mind and I would like to stay in an editor as much as possible, since I am not a programmer. What would be the simplest way to place 3D objects in a level prebuilt in TXB?
One reason I would like 3D is for the perspective view of objects vs orthographic.
For 3D objects to have perspective would I have to use a "T3DCameraComponent"?
Sean
03/08/2008 (11:23 pm)
Hey man, thanks for the reply! I was thinking of doing the latter considering the Platformer Kit was coded with 2D in mind and I would like to stay in an editor as much as possible, since I am not a programmer. What would be the simplest way to place 3D objects in a level prebuilt in TXB?
One reason I would like 3D is for the perspective view of objects vs orthographic.
For 3D objects to have perspective would I have to use a "T3DCameraComponent"?
Sean
#3
If you already have the platformer kit, give this a try. If not, first try making a couple or simple prototypes by creating simple 2D game levels. Keep in mind that the platformer kit is great, but isn't intended to be used in this way, so you will need to change the player animation code to work with a 3D player instead of a 2D animation sprite player.
John K.
03/09/2008 (10:28 am)
There are a lot of great reasons to go down this path. For me, it's because I can create 3D models and animations much better than I can draw 2D characters. Here's a code sample that creates a 3D model using the T2DShape3D object. This is a really nice class that lets you place a 3D object in a 2D scene. note the key methodss that set the layer, position, and rotation. If you wanted to create an isometric/perspective game, you can simply play with the rotation to get the model to look right (not play with the camera component).public void CreatePlayer()
{
T2DShape3D shape = new T2DShape3D();
shape.Name = "Player";
shape.SetShape(@"data\shapes\boombot\orange_player.dts");
//set the size of the model in the scene
shape.ShapeScale = new Microsoft.Xna.Framework.Vector3(10);
//set the position of the model in the scene
shape.SetPosition(Vector2.Zero, true);
//the the rotation of the model
shape.Rotation2 = new Vector3(0, 90, 0);
//set the layer
shape.Layer = 0;
shape.Components.AddComponent(new MovementComponent());
shape.Components.AddComponent(new T2DPhysicsComponent());
TorqueObjectDatabase.Instance.Register(shape);
} If you already have the platformer kit, give this a try. If not, first try making a couple or simple prototypes by creating simple 2D game levels. Keep in mind that the platformer kit is great, but isn't intended to be used in this way, so you will need to change the player animation code to work with a 3D player instead of a 2D animation sprite player.
John K.
#5
Sean
03/09/2008 (9:58 pm)
Thanks John for the help! I'll probably have more questions as soon as I get my hands more dirty on this.Sean
#6
Also, the getter for Rotation2 always returns (0,0,0). There's no TODO comment in the code but I'm guessing this could be replaced by some code that determines the rotation from the ShapeMatrix. ShapeMatrix.Decompose could be used to get the rotation as a quaternion and then ...
But I'm an AI guy, not a graphics guy, so I'm just guessing.
03/09/2008 (10:56 pm)
Tried this. It works, except the rotation should be in radians.//the the rotation of the model (front view)
shape.Rotation2 = new Vector3((float)Math.PI, (float)Math.PI/2, 0);Also, the getter for Rotation2 always returns (0,0,0). There's no TODO comment in the code but I'm guessing this could be replaced by some code that determines the rotation from the ShapeMatrix. ShapeMatrix.Decompose could be used to get the rotation as a quaternion and then ...
But I'm an AI guy, not a graphics guy, so I'm just guessing.
#7
Sean
03/13/2008 (1:23 pm)
Would either of you guys mind sending me a simple example project of this?Sean
#8
Here's the essential part of what you want. Just stuff it in your Starter Game Game.cs. My bouncingBall1_5.txscene is just a ball with world limits and some velocity bouncing around and script name "gameBall"...easy to whip up in TXB. The boombot's head tracks the ball in this example.
Thanks to John K. for suggesting this cool feature!
03/13/2008 (1:39 pm)
@Sean,Here's the essential part of what you want. Just stuff it in your Starter Game Game.cs. My bouncingBall1_5.txscene is just a ball with world limits and some velocity bouncing around and script name "gameBall"...easy to whip up in TXB. The boombot's head tracks the ball in this example.
protected override void BeginRun()
{
base.BeginRun();
// load our scene objects from XML. Torque X is designed to load game data from XML, but this is not strictly required;
// anything in an XML file can also be created manually in C# code. The SceneLoader is provided by TorqueGame and can be
// used to load and unload XML files.
SceneLoader.Load(@"data\levels\bouncingBall1_5.txscene");
CreatePlayer();
}
public void CreatePlayer()
{
T2DShape3D shape = new T2DShape3D();
shape.Name = "Player";
shape.SetShape(@"data\shapes\boombot\orange_player.dts");
//set the size of the model in the scene
shape.ShapeScale = new Microsoft.Xna.Framework.Vector3(100);
//set the position of the model in the scene
shape.SetPosition(new Vector2(0, shape.Shape.Center.Y*shape.ShapeScale.Y), true);
//the the rotation of the model
shape.Rotation2 = new Vector3((float)Math.PI, (float)Math.PI/2, 0);
//set the layer
shape.Layer = 20;
shape.Components.AddComponent(new MovementComponent());
shape.Components.AddComponent(new T2DPhysicsComponent());
shape.AddThread("Main", "run", true);
shape.AddThread("Look", "look", false);
shape.AddThread("HeadSide", "headside", false);
shape.OnAnimationTrigger = OnAnimationTrigger;
shape.OnAnimateShape = OnAnimateShape;
TorqueObjectDatabase.Instance.Register(shape);
}
public void OnAnimationTrigger(int channel)
{
switch (channel)
{
case 1:
// left foot down ...
// add foot puff
// add foot step sound
// apply force
break;
case 2:
// right foot down
// add foot puff
// add foot step sound
// apply force
break;
}
}
public void OnAnimateShape(float dt)
{
// shape and ball should be saved in member fields
// instead of looked up each frame! but good enough for
// this quick and dirty test
T2DShape3D shape =
TorqueObjectDatabase.Instance.FindObject<T2DShape3D>("Player");
T2DSceneObject ball =
TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("gameBall");
float y = ball.Position.Y;
// the constants below should not be hard coded but determined
// elsewhere...but good enough for this test
float look = (y+384.0f)/768.0f;
float x = ball.Position.X;
float headside = 1.0f-(x + 512.0f) / 1024.0f;
shape.SetSequence("Look", "look", look);
shape.SetSequence("HeadSide", "headside", headside);
}Thanks to John K. for suggesting this cool feature!
#9
For me I couldn't just put "Vector#" or "Vector#", I had to put "Microsoft.Xna.Framework.Vector#". mmh... but still the model is not showing up, ugh. =)
03/13/2008 (5:07 pm)
Hey Scott, Thanks for the example. For me I couldn't just put "Vector#" or "Vector#", I had to put "Microsoft.Xna.Framework.Vector#". mmh... but still the model is not showing up, ugh. =)
#10
using Microsoft.Xna.Framework;
Model is not showing up? Are you trying to get a 3D model in a 2D game, or a 3D model in a 3D game? I an post a quick sample project if I know which way you're aiming.
John K.
03/13/2008 (5:14 pm)
To have the code reference just Vector2 or Vector3, add the namespace to the top of your code...using Microsoft.Xna.Framework;
Model is not showing up? Are you trying to get a 3D model in a 2D game, or a 3D model in a 3D game? I an post a quick sample project if I know which way you're aiming.
John K.
#11
03/13/2008 (5:19 pm)
3d in 2d. Thanks
#12
You can download from: www.envygames.com/share/A3DManInA2DWorld.zip
John K.
03/13/2008 (6:00 pm)
Okay, this is probably the best I can do in a 15 minute break... I've created a new 2D Game project in the new Torque X 2.0 format. It's all zipped up and uploaded to my server. After you download and open up the project, you will need to add the project reference to the Torque X DLL. From there, you should be able to build and run the sample. The sample will run a scene that has the GGLogo in the center and the Boombot 3D model, attached to a MovementComponent, so you can move him around the scene. This should be a good starting point for you.You can download from: www.envygames.com/share/A3DManInA2DWorld.zip
John K.
#13
03/13/2008 (6:20 pm)
Thanks again John!
#14
mindcrafters.net/Portals/0/Cider/Archive/T2D%203D.zip
03/13/2008 (6:24 pm)
That's great John. Here's my version:mindcrafters.net/Portals/0/Cider/Archive/T2D%203D.zip
#15
03/13/2008 (6:36 pm)
Hey Scott, Thank you as well! I really appreciate all the help.
#16
03/14/2008 (7:31 pm)
Is there any way to add perspective "distortion"(back smaller than front) to the 3d objects?
#17
John K.
03/14/2008 (7:56 pm)
To just the model, not really... well, not easily. I suppose you could get a hold of the vertex positions that make up the model and manually set their position, but this is going to be really hard. If you mean distorting the entire scene, maybe you can play with the field of view on the camera to work up a distortion effect. Another approach could be to use a distorted normal map and then use a refraction shader for the effect (a lot like explosion shock wave effect in the TankBuster sample). John K.
#18
03/14/2008 (8:10 pm)
How would I adjust the FOV?
#19
public void CreateCam()
{
T2DSceneCamera cam = new T2DSceneCamera();
cam.Name = "Camera";
cam.SetPosition(Vector2.Zero, true);
cam.Extent = new Vector2(100, 75);
cam.FOV = (70);
TorqueObjectDatabase.Instance.Register(cam);
}
but the "FOV" doesn't seem to change anything.
03/14/2008 (8:56 pm)
I tried this:public void CreateCam()
{
T2DSceneCamera cam = new T2DSceneCamera();
cam.Name = "Camera";
cam.SetPosition(Vector2.Zero, true);
cam.Extent = new Vector2(100, 75);
cam.FOV = (70);
TorqueObjectDatabase.Instance.Register(cam);
}
but the "FOV" doesn't seem to change anything.
#20
GarageGames.Torque.GFX.GFXDevice.Instance.SetFrustum(3.0f, 1.33f, 0.1f, 1000.0f);
John K.
03/14/2008 (9:02 pm)
Try adding something like this somewhere in your game... maybe in the BeginRun() method.GarageGames.Torque.GFX.GFXDevice.Instance.SetFrustum(3.0f, 1.33f, 0.1f, 1000.0f);
John K.
Associate John Kanalakis
EnvyGames
John K.