Game Development Community

Mount Objects

by Sean T. Boyette · in · 10/26/2008 (8:30 pm) · 5 replies

John -
I am having some difficulty with mounting an object.
I created a player character adding the following to my createplayer:
//Mounting Component
            T3DMountComponent componentMount = new T3DMountComponent();
            componentMount.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentMount);
I have created the sword via the following no mount component:
public void CreateSword()
        {
            TorqueObject objSword = new TorqueObject();
            objSword.Name = "SwordObject";

            //Scene Component
            T3DSceneComponent componentScene = new T3DSceneComponent();
            componentScene.Position = new Vector3(1024, 1036, 260);
            componentScene.SceneGroup = "SwordObject";
            objSword.Components.AddComponent(componentScene);

            //Render Component - DTS Shape
            T3DTSRenderComponent componentRender = new T3DTSRenderComponent();
            componentRender.ShapeName = @"data\shapes\Sword\Sword.dts";
            componentRender.SceneGroupName = "SwordObject";
            objSword.Components.AddComponent(componentRender);

            TorqueObjectDatabase.Instance.Register(objSword);
        }
and try to mount the sword via:
public void MountSwordToPlayer()
        {
            TorqueObject objPlayer = TorqueObjectDatabase.Instance.FindObject<TorqueObject>("PlayerObject");
            TorqueObject objSword = TorqueObjectDatabase.Instance.FindObject<TorqueObject>("SwordObject");

            if (objPlayer != null && objSword != null)
            {
                T3DMountComponent componentMount = objPlayer.Components.FindComponent<T3DMountComponent>();
                T3DSceneComponent componentSceneChild = objSword.Components.FindComponent<T3DSceneComponent>();

                componentMount.MountObject(componentSceneChild, "Mount0", "mountPoint");
            }
        }

calling everything in this order:
CreatePlayer();
            CreateSword();
            MountSwordToPlayer();


when not mounting (just showing the sword) I can see it properly.
However, when I mount it - it disapears.

#1
10/26/2008 (8:32 pm)
Nevermind - user error:
for those having the same issue
componentScene.Position = new Vector3(1024, 1036, 260); makes it offset
remove that from the create sword
#2
10/28/2008 (10:03 am)
Sean,

When you say "No Mount Component" above what do you mean. I understand the concept of mounting nodes in the DTS file but I'm not following the statement.

Also I've used your code above to bring in my dts object and when the
"ComponentScene.Posiition = new Vector3(1024, 1036,260);
line is there, I see my object. When it is commented out my object disappears and is not mounted to the player. Any ideas?

Thanks,
Jeff
#3
10/28/2008 (11:53 am)
Jeff -
"no Mount Component" means that I did not add this to the object
//Mounting Component
            T3DMountComponent componentMount = new T3DMountComponent();
            componentMount.SceneGroupName = "PlayerObject";
            objPlayer.Components.AddComponent(componentMount);

my current version of CreateSword is as follows:
public void CreateSword()
        {
            //See if Sword exists
            TorqueObject tmpPlayer = TorqueObjectDatabase.Instance.FindObject<TorqueObject>("SwordObject");
            if (tmpPlayer != null)
            {
                TorqueObjectDatabase.Instance.Unregister(tmpPlayer);
            }     

            TorqueObject objSword = new TorqueObject();
            objSword.Name = "SwordObject";

            //Scene Component
            T3DSceneComponent componentScene = new T3DSceneComponent();
            componentScene.SceneGroup = "SwordObject";
            objSword.Components.AddComponent(componentScene);

            //Render Component - DTS Shape
            T3DTSRenderComponent componentRender = new T3DTSRenderComponent();
            componentRender.ShapeName = @"data\shapes\Sword\Sword.dts";
            componentRender.SceneGroupName = "SwordObject";
            objSword.Components.AddComponent(componentRender);

            TorqueObjectDatabase.Instance.Register(objSword);
        }
My Parend Node DTS has a Mount called Mount0, the child (sword) has a Mount called mountPoint.
I use Showtool to validate this. One thing to note -Show tool seems to have a offset bug - anyways..
I roughly validate that the mount is working in show tool pro, and then execute it in my game.

I am nearing when I will feel comfortable showing you guys my progress, just a few more details.
Sean
#4
10/31/2008 (10:58 am)
Sean,
Got my mounting to work!

I believe it was a matter of the exporter stripping out the mount point! Didn't have a config file set up. Redid that and now it works!

Thanks for the example code!
Jeff
#5
11/03/2008 (8:53 am)
Ahh!!! Great!