OnCollision Delegates
by Kent Frauendienst · in Torque X 2D · 03/04/2010 (11:09 pm) · 3 replies
I'm working on a platformer currently, and I'm having kind of an issue with the implementation of an onCollision delegate that I want to use for checking to see if the player is on the ground. Specifically, I'm having a problem with actually getting the OnCollision delegate to compile.
I looked at the documentation for its example of how to implement one, and I've looked through some forum posts, but haven't really found something that works. I followed the documentation precisely, but it has some vagaries in it: For example, where exactly you have to put this method. My understanding is that it goes inside of a component, but it doesn't compile the private static variable shown in the example here - the specific error being about the number of overloads not matching.
I'm hoping I'm just missing something simple here, but does anyone have a working example or any corrections or insight to the example in the documentation that they could provide?
I looked at the documentation for its example of how to implement one, and I've looked through some forum posts, but haven't really found something that works. I followed the documentation precisely, but it has some vagaries in it: For example, where exactly you have to put this method. My understanding is that it goes inside of a component, but it doesn't compile the private static variable shown in the example here - the specific error being about the number of overloads not matching.
I'm hoping I'm just missing something simple here, but does anyone have a working example or any corrections or insight to the example in the documentation that they could provide?
About the author
#2
You set the YourSceneObject.Collision.OnCollision = OnThisCollision; and then perform your logic in there.
The ResolveActorCollision is a specific method, however, that is likely to only be able to be called in the YourSceneObject class, unless you can correctly reference it.
(Note that PlayerActorComponent is specific to my code)
Hope this helps you get further.
04/18/2010 (5:30 am)
I just posted this on another thread and stumbled across this one.public void OnThisCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
{
if (theirObject.Components.FindComponent<PlayerActorComponent>() != null)
{
resolve = ResolveActorCollision;
ourObject.MarkForDelete = true;
}
else
{
resolve = null;
}
}You set the YourSceneObject.Collision.OnCollision = OnThisCollision; and then perform your logic in there.
The ResolveActorCollision is a specific method, however, that is likely to only be able to be called in the YourSceneObject class, unless you can correctly reference it.
(Note that PlayerActorComponent is specific to my code)
Hope this helps you get further.
#3
04/18/2010 (9:52 am)
@kent: also, if you're making a platformer the Platformer Starter Kit will handle this stuff for you.
Torque Owner Seth Turner
The Space Warrior Tutorial covers OnCollision in section "6. Tis Only a Fleshwound" which is what I've used as an example for getting my OnCollision delegates to work.
You can get all the tutorials here:
www.torquepowered.com/documentation/tx
Just click the "Torque X Tutorial Set" link.
Also, I noticed that no version of Torque X is listed in the "Torque Products Owned" part of your profile so make sure you're not trying to do Torque X stuff in the regular Torque Game Builder :P