How do I get a reference to the Force object I created in TXB?
by rwillis · in Torque X 2D · 10/23/2007 (10:43 pm) · 2 replies
I created a force in TXB in the force component, gave it a name, and it seems to work, but how do I reference that Force object in code? I tried using "TorqueObjectDatabase.Instance.Findobject" but it didn't work. Thanks.
About the author
#2
10/24/2007 (6:01 am)
Yes, that helped much. Thank you. So to change the strength in code of a Force object created in TXB I would have to use the ValueInterface that it creates? What about if I want to change its direction in code? Or should I just create the force object in code to begin with (so that I have a reference to it so I can change the properties)?
Associate John Kanalakis
EnvyGames
T2DSceneObject objectWithForceComponent = TorqueObjectDatabase.Instance.FindObject<T2DSceneObject>("MyObject"); T2DForceComponent forceComponent = objectWithForceComponent.Components.FindComponent<T2DForceComponent>(); foreach (T2DForceComponent.Force aForce in forceComponent.Forces) { if (aForce.Name.CompareTo("MyForce") == 0) { float val = aForce.MaxStrength; } }This is about as direct as you can get to an individual force. Hope that helps...
John K.