PDA

View Full Version : A Problem with iterator (identify owner/not owner)



F4ll_ouT
05-18-2012, 08:17 PM
Hi all,
well my question is pretty simple I hope. I wrote an Iterator and it seem to work.
But I use a third person camera and I'm checking for visible Pawns in range. It looks like my condition was written wrong because I don't want the owner pawn to be recognized but it does.


exec function CheckEnemy()
{
local Pawn checked;

ForEach VisibleActors( class'Pawn', checked, 64,(Pawn != None) ? Pawn.Location : Location )
{
if (checked != none && checked != Owner)
{
`log("Enemy In Range");
}
else if (checked != none && checked == Owner)
{
`log("Something in Range");
}
else
{
`log("Nothin in Range");
}
}
}

When I start the Iterator in game, I just get:
"Enemy in Range" although I can just see myself.
I get
"Enemy in Range"
"Enemy in Range"
when I see myself and the enemy pawn at once. What have I done wrong? Can someone help me with this?

Blade[UG]
05-18-2012, 10:29 PM
64 units around the location of your Pawn is probably barely enough to get beyond your Pawn.

Also, I believe that there is no Owner of a PlayerController - PlayerController typically owns a Pawn, not the other way around (unless you've followed one of the tutorials around here from ages ago that would botch that relationship up). My suggestion is to treat the PlayerController as if it's not an actual physical thing in the world, and use your Pawn for that sort of thing.

However, if this code can run in a context where there is no Pawn, as it seems to indicate, then obviously you can throw some of that suggestion out.

F4ll_ouT
05-19-2012, 09:24 AM
I'm not sure if I totally understood what you told me.
Do you want me to seek for Playercontrollers instead of Pawns?
Your first sentence irritated me. I thought the radius value does check anything within the radius, not beyond.
I think your last sentence does not apply on my case, because I'm pretty sure that it indicates my own pawn at least.

But the most important thing is, what do I have to do now? Do I really have to check for Playercontrollers instead of pawns? Are Controllers handled as actors after all? Well I will try this evening thx for reply

rquester
05-19-2012, 10:20 AM
F4ll_ouT
Maybe you need self or Pawn not Owner? (if your code in Pawn class - self, in controller - Pawn, it seems that this is controller class and you need Pawn).
P.S.: In foreach works continue and break operators, it can simplify code sometimes.

Spoof
05-19-2012, 10:33 AM
exec function CheckEnemy()
{
local Pawn checked;

foreach VisibleActors( class'Pawn', checked, 64, (Pawn != None) ? Pawn.Location : Location )
{
// unnecessary to test for None
if( checked != Pawn )
{
`log("Enemy In Range");
}
else
{
`log("Nothin in Range");
}
}
}

Blade[UG]
05-20-2012, 05:02 AM
I'm sorry to have irritated you. o.O I mean, if you're looking for someone only within 64 units, at least in "normal" Unreal scale, that's only approximately 2/3rd the height of a UTPawn distance wise that you are searching.

You want to search for Pawns, but you're checking to see if what you hit is the Owner. I assumed that your code is in your PlayerController, and the Owner of a PlayerController is usually None, I think.

Overall, I think Spoof has written what you're looking for there, I was trying to explain why it wasn't working :)