castCollision(20.0) works but castCollision(0) doesn't
by Justin Mosiman · in Torque Game Builder · 01/24/2009 (5:22 pm) · 5 replies
Hello,
I have two objects that will collide with each other, and I want to know the distance they are apart, so I think castCollision would be the right tool for the job. Based on the castCollision documentation (tdn.garagegames.com/wiki/TGB/Reference:_t2dSceneObject_Collision_Methods#castCol...), a castCollision(0.0) should report the first object that the calling object collides with, without factoring in time. I did this and the castCollision didn't find any object.
If I do a castCollision(20.0) (or any large arbitrary number), the calling object find that object that it is about to hit. To me this says that my collision parameters are correct (send/receive on both objects), and it is a problem with castCollision.
Has anybody else noticed this?
Thanks,
Justin
I have two objects that will collide with each other, and I want to know the distance they are apart, so I think castCollision would be the right tool for the job. Based on the castCollision documentation (tdn.garagegames.com/wiki/TGB/Reference:_t2dSceneObject_Collision_Methods#castCol...), a castCollision(0.0) should report the first object that the calling object collides with, without factoring in time. I did this and the castCollision didn't find any object.
If I do a castCollision(20.0) (or any large arbitrary number), the calling object find that object that it is about to hit. To me this says that my collision parameters are correct (send/receive on both objects), and it is a problem with castCollision.
Has anybody else noticed this?
Thanks,
Justin
#2
What if I have this situation:

The turret (green) is mounted on top of a base (blue). There is an enemy (red) heading towards the base, and I want the turret to be able to shoot the enemy if it gets within in a certain distance. Would castCollision work in this situation? I haven't tried it yet, but I don't think it would because the enemy would never collide with the turret.
In TGE/TGEA the method that I would use Container::castRay, but I haven't seen that available in TGB. Am I just missing it?
Thanks for all of your help, I really appreciate it.
Justin
01/25/2009 (2:15 pm)
Ohh, that makes sense, I read the docs wrong.What if I have this situation:

The turret (green) is mounted on top of a base (blue). There is an enemy (red) heading towards the base, and I want the turret to be able to shoot the enemy if it gets within in a certain distance. Would castCollision work in this situation? I haven't tried it yet, but I don't think it would because the enemy would never collide with the turret.
In TGE/TGEA the method that I would use Container::castRay, but I haven't seen that available in TGB. Am I just missing it?
Thanks for all of your help, I really appreciate it.
Justin
#3
01/25/2009 (10:31 pm)
What about this?%dist = VectorDist(%turret.getPosition(), %enemy.getPosition());
#4
01/29/2009 (3:16 pm)
That's a pretty yummy solution Stefan. However in order to do a more event based detection I would suggest creating a circular trigger mounted to the turret, and just handle the attacking inside the "onEnter" callback method of the trigger.. that would probably scale a little better if you had a trillion guys on the screen. An added bonus is you can scale your range simply by scaling the size of the trigger, which will move around with the turret.. that is if it moves
#5
One thing to consider is that you want to be checking collisions (sending) from the least amount of objects. In that respect, if you've got less turrets than enemies then get the turrets to check for enemies and the opposite if you've got more turrets than enemies.
A quick distance check is always preferred before perhaps dropping to the more expensive collision check. You could even use triggers and then perhaps a more detailed check using cast-collision if required.
There are many ways to achieve this but it does depend mostly if you're interested in line-of-sight as well.
Melv.
02/02/2009 (9:04 am)
Some good advice here.One thing to consider is that you want to be checking collisions (sending) from the least amount of objects. In that respect, if you've got less turrets than enemies then get the turrets to check for enemies and the opposite if you've got more turrets than enemies.
A quick distance check is always preferred before perhaps dropping to the more expensive collision check. You could even use triggers and then perhaps a more detailed check using cast-collision if required.
There are many ways to achieve this but it does depend mostly if you're interested in line-of-sight as well.
Melv.
Associate Phillip O'Shea
Violent Tulip