Page 1 of 1

Can't SetLocation() in a pawn?

PostPosted: Thu Feb 17, 11 1:53 pm
by Cozmo
Yes more NPC movement stuff. :oops: So I have a pawn that can be ordered to follow you in MP. I want it so that they will teleport to you once you're too far away from them, so they can "follow" you on trains around the city, get past BlockMonsters and so on.

The code seems fine - the debug message shows up when it should be called, but they're just not doing it? This is the relevant code so far...

Code: Select all
   if((DXP != None) && (Enemy == None))
   {
      if(VSize(Location-DXP.Location) > 1200)
      {
         self.SetLocation(DXP.Location);
         broadcastmessage("debug: tele");
      }
      else if(VSize(Location-DXP.Location) < 200)
      {
         gotoState('Standing');
      }
      else
      {
         GetMoving();
      }
   }


This code is in the pawn in a Timer(), with DXP being the player. I've tried it with and without "self." before the function. Something to note is that the pawn is in a new following state, but this is global code. Anyone have any idea about this? I wanted to release the mod later today but this is important (and frustrating).

PostPosted: Thu Feb 17, 11 7:08 pm
by Dae
did you try logging DXP.Location?

PostPosted: Thu Feb 17, 11 8:03 pm
by Cozmo
Just tried that. It seems to have my location fine

Image

This problem is incredibly silly.

PostPosted: Fri Feb 18, 11 1:26 am
by Dae
wild guess... try SetLocation(DXP.Location+vect(2,2,2));

PostPosted: Fri Feb 18, 11 2:34 am
by Cozmo
Ooh, it does seem to be a collision thing (I suspected, but no idea how to check native functions). Made it slightly bigger +(100,100,100) and it works now. Will now figure out how to make sure NPCs don't get stuck in walls. Thanks a lot Dae :)

PostPosted: Fri Feb 18, 11 8:33 pm
by Cozmo
For anyone interested, I changed it so that the NPC spawns 2 feet behind the player, so it'll be cleaner / less chance of getting stuck in something.

Code: Select all
   local vector loc;

   loc = DXP.Location;
   loc -= 32.0 * DXP.CollisionRadius * vector(DXP.ViewRotation);
   loc.Z += DXP.CollisionHeight * 0.9;

   SetLocation(loc);