Custom Components
by Sharpie · in Torque X 3D · 04/11/2010 (5:13 pm) · 11 replies
Hi all,
I don't understand how to add custom components to the objects in the 3D Builder. I create a project in XNA, add a custom component, build the project, etc. I then open the project in Builder, drag an object into the game (in this case a player), and click the green plus sign to add a component. But only the original components are there, none of the ones I've created are available. How do I add custom components? I know how to do it in the 2D Builder, and the TorqueX book claims that it's possible for the 3D, but I just haven't figured it out. Any help would be awesome, thanks! :)
I don't understand how to add custom components to the objects in the 3D Builder. I create a project in XNA, add a custom component, build the project, etc. I then open the project in Builder, drag an object into the game (in this case a player), and click the green plus sign to add a component. But only the original components are there, none of the ones I've created are available. How do I add custom components? I know how to do it in the 2D Builder, and the TorqueX book claims that it's possible for the 3D, but I just haven't figured it out. Any help would be awesome, thanks! :)
#2
What I have is a soccer field and a soccer player. My soccer player I originally placed into the game manually, without the Builder. But once I started having trouble placing the field itself, I switched over to placing the objects via the Builder. But my soccer player lost his MovementComponent that I'd written, so he no longer walked. That's what I was trying to add. But if I'm understanding correctly, this isn't possible?
Bummer. Guess I'll have to go back and figure out how to add the field manually. :(
Oh, another question concerning the Builder. How come the objects I add manually (the soccer player, the ball, etc.) don't show up in the Builder? They're there when I run the game, and they work perfectly. But they don't exist in the Builder! I find that...annoying. Is it because the Builder pulls from the XML file? Because I suppose my soccer player and ball weren't added via that, but via my Game.cs class. :|
04/12/2010 (3:47 pm)
Hmm...well that's disappointing. So does that mean the Builder is no good to me for placing objects that are going to need custom components? What I have is a soccer field and a soccer player. My soccer player I originally placed into the game manually, without the Builder. But once I started having trouble placing the field itself, I switched over to placing the objects via the Builder. But my soccer player lost his MovementComponent that I'd written, so he no longer walked. That's what I was trying to add. But if I'm understanding correctly, this isn't possible?
Bummer. Guess I'll have to go back and figure out how to add the field manually. :(
Oh, another question concerning the Builder. How come the objects I add manually (the soccer player, the ball, etc.) don't show up in the Builder? They're there when I run the game, and they work perfectly. But they don't exist in the Builder! I find that...annoying. Is it because the Builder pulls from the XML file? Because I suppose my soccer player and ball weren't added via that, but via my Game.cs class. :|
#3
04/12/2010 (5:28 pm)
What I did was place the objects where I wanted, and such then attached my components in code. It worked great.
#4
04/12/2010 (6:01 pm)
Ah-ha! That's what I've been trying to work out. I was hoping, hoping, hoping that was possible, but I haven't been able to figure it out. So, how did you attach the components in code? If I can understand that, I can be on my way! Thanks! :)
#5
you can call an initialize function. In the Initialize function you attach your components.
TaDa! you got a dude!
Any other stuff that you dropped into the scene will be there, so you can go run the dude around etc.
04/12/2010 (7:08 pm)
After you load the scene:Game.Instance.SceneLoader.Load(@"datalevelslevelData.txscene"); makeDude();
you can call an initialize function. In the Initialize function you attach your components.
void makeDude()
{
TorqueObject dudeTmp = TorqueObjectDatabase.Instance.FindObject<TorqueObject>("dudeTemplate");
TorqueObject dude = (TorqueObject)dudeTmp.Clone();
dude.Name = "PlayerObject";
T3DSceneComponent dudeScene = dude.Components.FindComponent<T3DSceneComponent>();
dudeScene.Position = new Vector3(-202, -89, 24);
//add the animation component
T3DAnimationComponent componentAnimation = new T3DAnimationComponent();
componentAnimation.SceneGroupName = dudeScene.SceneGroup;
dude.Components.AddComponent(componentAnimation);
//add the player movement conmponent
MovementComponent3D componentMovement = new MovementComponent3D();
componentMovement.SceneGroupName = dudeScene.SceneGroup;
dude.Components.AddComponent(componentMovement);
TorqueObjectDatabase.Instance.Register(dude);
}TaDa! you got a dude!
Any other stuff that you dropped into the scene will be there, so you can go run the dude around etc.
#6
04/12/2010 (7:12 pm)
Ah! Thanks so much! I feel like I should have known that already, but alas. I often overlook the obvious. I'm going to go try that out and see what I get. So excited! :)
#7
Edit: My pause menu is working, which is accessed through the MovementComponent, so something's working. But somewhere it's also getting hung up. Grrr...
04/12/2010 (8:15 pm)
Hmm...okay, well everything compiles and runs fine, but Bob (my player) doesn't move. He just sits there. Also, the camera isn't tied to him anymore, but that's coded in MovementComponent. So I'm assuming something's messing up between Bob and the MovementComponent. Any ideas? :|Edit: My pause menu is working, which is accessed through the MovementComponent, so something's working. But somewhere it's also getting hung up. Grrr...
#8
change the camera from free camera:
in your movement component _onRegister
put this at the end of your UpdateInput() method
OK that's pretty simple camera stuff, if you search the forums you will find more sophisticated camera stuff, like over the shoulder cams.
04/12/2010 (9:00 pm)
From John's book:change the camera from free camera:
<T3DCameraComponent type="GarageGames.Torque.T3D.T3DCameraComponent" name="CameraComponent">
in your movement component _onRegister
_camera = TorqueObjectDatabase.Instance.FindObject<T3DCameraComponent>("CameraComponent");put this at the end of your UpdateInput() method
if (_camera != null)
{
Vector3 cameraPosition = Vector3.Add(SceneGroup.Position, _cameraOffset);
_camera.SetTransform(Matrix.CreateTranslation(cameraPosition), false);
}OK that's pretty simple camera stuff, if you search the forums you will find more sophisticated camera stuff, like over the shoulder cams.
#9
I'll let you know if I have anymore questions, but right now it's all good. :)
04/13/2010 (11:00 am)
Awesome! I didn't realize that the Builder was overwriting my T3D Camera. Cause I already had it coded, but the XML was changed back to FreeCamera when I saved the scene. That's not fun. But now it works! Thanks much! :)I'll let you know if I have anymore questions, but right now it's all good. :)
#11
Next question: My field doesn't have a collision block like I thought I put around it. Bob doesn't fall through because of the MovementComponent, and runs around pretty darn realistically. But the ball falls right through the field and bounces away along the terrain I've got in the background. Any ideas on fixing that? I added the components that John's book suggested to fixing that, but unfortunately it didn't work. You think it might be because of the model itself? Or can that be coded exclusively into Torque, the collision, that is?
I'd like to put a complete box around the field, that way Bob can't run off the field, and neither can the ball. Also that the ball won't fall right through. As far as I know, Bob can still kick the ball (cause he could before), but I haven't been able to find out, because the ball always drops away immediately. Although...come to think of it...I think the field does have a collision block. Because when the soccer ball runs into it (which it does immediately, since they're spawning in the same basic spot), the ball takes off. It didn't used to do that. But how can I make the field impenetrable so that the ball stays on top of it? I guess that's my main question. :)
04/13/2010 (8:56 pm)
Me, too! It's already looking so much better. I've got the 3rd person camera going, which is great. :)Next question: My field doesn't have a collision block like I thought I put around it. Bob doesn't fall through because of the MovementComponent, and runs around pretty darn realistically. But the ball falls right through the field and bounces away along the terrain I've got in the background. Any ideas on fixing that? I added the components that John's book suggested to fixing that, but unfortunately it didn't work. You think it might be because of the model itself? Or can that be coded exclusively into Torque, the collision, that is?
I'd like to put a complete box around the field, that way Bob can't run off the field, and neither can the ball. Also that the ball won't fall right through. As far as I know, Bob can still kick the ball (cause he could before), but I haven't been able to find out, because the ball always drops away immediately. Although...come to think of it...I think the field does have a collision block. Because when the soccer ball runs into it (which it does immediately, since they're spawning in the same basic spot), the ball takes off. It didn't used to do that. But how can I make the field impenetrable so that the ball stays on top of it? I guess that's my main question. :)
Torque 3D Owner Henry Shilling
Smokin Skull
I think we are going to have to accept that we'll have to wait for the new builder to release. They have said it's in QA so we'll see.