See if ally is in firing path?
by Christian · in Torque 2D Beginner · 05/16/2013 (4:56 am) · 10 replies
Trying to come up with a way to check if ally is in a firing path before making the shot.
Could draw a line from point a to b, but that would only be able to give a range from the center of the line and not actually notice the kinematic objects (I think).
Maybe there is a way to draw have 'dots' dropped every few feet and do a small radius search from each of those for the kinematic objects.
Is there a more simple way I'm missing?
Could draw a line from point a to b, but that would only be able to give a range from the center of the line and not actually notice the kinematic objects (I think).
Maybe there is a way to draw have 'dots' dropped every few feet and do a small radius search from each of those for the kinematic objects.
Is there a more simple way I'm missing?
#3
I don't remember seeing PickLine(), but I should hope it would exhibit similar behavior.
05/16/2013 (7:01 pm)
I think pickRay() returns a list of object id's in order from ray start to ray end, you can search through it to see if anything "obstructs line of sight".I don't remember seeing PickLine(), but I should hope it would exhibit similar behavior.
#4
05/16/2013 (11:20 pm)
Is there a document or place that shows pickray being used? Haven't found a useable example yet.
#5
05/17/2013 (1:56 am)
Yes, the PickingToy that is included in the Sandbox shows how pickRay is used.
#6
I don't see the code ever being called in the Sandbox. Just a bunch of
Which code is actually creating the Ray? I'm totally lost.
05/18/2013 (10:02 am)
The PickingToy example code is highly confusing to me for some reason.I don't see the code ever being called in the Sandbox. Just a bunch of
function PickingToy::*******statements.
Which code is actually creating the Ray? I'm totally lost.
#7
%picked becomes a string containing the handles of objects the ray went through. You can get the total count of handles using getWordCount() and get the handles themselves using getWord(). FYI, pickRay() belongs to the scene class, getWordCount() & getWord() are globals.
05/18/2013 (10:44 am)
Line 184 uses the function:%picked = SandboxScene.pickRay( PickingToy.RayStart, %worldPosition, "", "", PickingToy.PickMode );
%picked becomes a string containing the handles of objects the ray went through. You can get the total count of handles using getWordCount() and get the handles themselves using getWord(). FYI, pickRay() belongs to the scene class, getWordCount() & getWord() are globals.
#8
The %picked position is showing up in random places all over the map and only randomly returns objects where it shouldn't. Shouldn't those two echoes give the same result?
05/18/2013 (12:36 pm)
It's giving some strange results%pos1 = $activeSprite.getPosition();
%picked = myScene.pickRay(PickingToy.RayStart, %pos1, "", "", PickingToy.PickMode);
echo("Picked.position: " @ %picked.GetPosition());
echo("Pos1 position: " @ %pos1);The %picked position is showing up in random places all over the map and only randomly returns objects where it shouldn't. Shouldn't those two echoes give the same result?
#9
05/18/2013 (4:49 pm)
If %picked contains several handles, who knows what %picked.getPosition() is returning. You have to get the handles individually and use getPosition() on those. Also, are you sure your RayStart and %pos1 are being calculated properly.
#10
05/18/2013 (9:37 pm)
Something clicked and it makes sense now. I didn't understand what RayStart was. Things lined up after that.
Torque Owner practicing01
MourningDoveSoft