Terrain Collision Callback
by Brandon Fogerty · in Torque 3D Beginner · 02/17/2010 (12:20 am) · 2 replies
Hi. I purchased the Angel model and I am currently implementing some flying functionality. Basically, when the player lands on the ground, I want the Angel to walk around as normal. When the player holds the right mouse button, I want the player to change to a flying animation and fly through the air.
I am thinking about implementing this buy detecting a collision event with the terrain. When the player goes into fly mode, I will change the animation to the cyclic flying animation. However when the player collides with the terrain, I will stop the flying animation so that the player and use the basic movement animations. Does this sound like the right way to implement it with Torque? If so, I noticed the PlayerData::onCollision callback only gets called when the player collides with another 3d model but not the terrain. Is there a collision callback for the terrain? Thanks!
I am thinking about implementing this buy detecting a collision event with the terrain. When the player goes into fly mode, I will change the animation to the cyclic flying animation. However when the player collides with the terrain, I will stop the flying animation so that the player and use the basic movement animations. Does this sound like the right way to implement it with Torque? If so, I noticed the PlayerData::onCollision callback only gets called when the player collides with another 3d model but not the terrain. Is there a collision callback for the terrain? Thanks!
#2
I think it would give the player a little more control and choice in deciding whether or not s/he wants to be flying. I've always enjoyed being able to fly up high in games and drop to my doom only to begin flying again right before hitting the ground (eg. Spiderman)
Haha anyways, hope you get it working like you want!
02/17/2010 (5:57 pm)
Sounds like a neat idea. Just a suggestion though. Why not just allow the player to release the right mouse button and that would kill the flying animation.I think it would give the player a little more control and choice in deciding whether or not s/he wants to be flying. I've always enjoyed being able to fly up high in games and drop to my doom only to begin flying again right before hitting the ground (eg. Spiderman)
Haha anyways, hope you get it working like you want!
Torque Owner Daniel Buckmaster
T3D Steering Committee
Aha - try onImpact instead. onCollision only registers ShapeBase-derived objects, which the terrain isn't - however, onImpact works with SceneObjects, which the terrain is.
The function should look something like:
function PlayerBody::onImpact(%this,%obj,%col,%normal,%speed) { //%this is the Player's datablock //%obj is the Player //%col is the object that was hit //%normal is the normal of collision //%speed is the speed into the normal }Beware that onImpact is only called on collisions greater than PlayerData::minImpactSpeed, so if you set that to a value greater than 0, the player will be able to brush against the ground without walking on it.
Disclaimer: I'm checking against TGE1.5.2, but I see no reason for this to have changed in T3D.