Data Realms Fan Forums
http://45.55.195.193/

Quick question about choosing homing targets
http://45.55.195.193/viewtopic.php?f=73&t=39736
Page 1 of 2

Author:  cyclops0000 [ Sat Dec 22, 2012 7:58 pm ]
Post subject:  Quick question about choosing homing targets

Hey, I've been working on my KamiCrabs Mod, And I am trying to add homing crabs to it, the homing part works fine, but currently, it likes to lock on to the brain and aim towards that every time, is there a way to set it to ignore Brains?]


Thanks

P.S. Sorry for any confusion that has been caused by my account being deleted, the forums thought it was a spam bot, and thus deleted all my posts.

Author:  Asklar [ Sat Dec 22, 2012 8:09 pm ]
Post subject:  Re: Quick question about choosing homing targets

In the line where you search the potential target, put "and not actor:HasObjectInGroup("Brains")".

I've never used it, but it's used in the AI and saw it on the wiki, so I doubt that it won't work.

Author:  cyclops0000 [ Sat Dec 22, 2012 8:37 pm ]
Post subject:  Re: Quick question about choosing homing targets

I Tried that, but no dice. The crab still goes hurtling towards the brain.

Code:
function Update(self)
      
      if self:IsPlayerControlled() == true then
         if  UInputMan:KeyPressed(19) == true then
            self:GibThis()
         end
      end
      if self:IsPlayerControlled() == true then
            if MovableMan:IsActor(self.target) and not self.target:HasObjectInGroup("Brains") then
               if UInputMan:KeyPressed(6) == true then
               self.RotAngle = SceneMan:ShortestDistance(self.Pos,self.target.Pos,true).AbsRadAngle
               self.Vel = Vector(100, 0):RadRotate(self.RotAngle)
                  end
                  
               else
      
         self.shortestdistance = 1
         for actor in MovableMan.Actors do
      if actor.Team ~= self.ignoreteam then
         self.curdist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true).Magnitude
         if self.curdist < 500000 and (self.shortestdistance == -1 or self.shortestdistance ~= -1 and self.curdist < self.shortestdistance) then
            self.target = actor
            self.shortestdistance = self.curdist
         end
      end
   end
end
end
end
function Destroy(self)
      if self:IsPlayerControlled() == true then
         if UInputMan:KeyPressed(19) == False then
         self:GibThis()
      end
   end
end
function Create(self)
      self.ignoreteam = self.team
      end


I apologize for my atrocious tabbing.

Author:  Asklar [ Sat Dec 22, 2012 8:48 pm ]
Post subject:  Re: Quick question about choosing homing targets

Code:
      if actor.Team ~= self.ignoreteam and not actor:HasObjectInGroup("Brains") then



There is where it should go, in the part where you are checking which actors are possible candidates, in that way, the actor must be of another team and can't be a brain.

Try to fix your tabbing hehehe

Author:  cyclops0000 [ Sat Dec 22, 2012 8:56 pm ]
Post subject:  Re: Quick question about choosing homing targets

Alright, It ignores the brains now, but I just realized it doesn't actually home in on anything. It goes flying to the right, ignoring all actors. I probably should have noticed that before now...
I'm guessing the problem is with my rotation script?


edit: Yeah.. I'll work on my tabbing real real real soon...

Author:  Asklar [ Sat Dec 22, 2012 9:01 pm ]
Post subject:  Re: Quick question about choosing homing targets

Well, that script looks a bit wierd.

What is it attached to? An emitter? It doesn't seem like it.

Author:  cyclops0000 [ Sat Dec 22, 2012 9:19 pm ]
Post subject:  Re: Quick question about choosing homing targets

Well, what its supposed to do is look for the closest enemy, rotate the crab towards it, and set the velocity of the crab. The crab is still an actor, so there is no emitter

Author:  Asklar [ Sat Dec 22, 2012 9:51 pm ]
Post subject:  Re: Quick question about choosing homing targets

Is it printing any errors, or it just won't work?

Author:  cyclops0000 [ Sat Dec 22, 2012 10:16 pm ]
Post subject:  Re: Quick question about choosing homing targets

No errors, it just sends the crab flying to the right, regardless of where the enemy are.

Author:  Asklar [ Sat Dec 22, 2012 10:22 pm ]
Post subject:  Re: Quick question about choosing homing targets

Well, try reducing that 500000 distance into something smaller, like 250 for testing purposes. Try to make additional checks (printing the presetname of the target, for example, and making sure that it's ID is ~= 255).

Also, don't set the angle you get to RotAngle, since the RotAngle varies easily in any moment. Store it in another variable created by you.

Author:  cyclops0000 [ Sat Dec 22, 2012 11:56 pm ]
Post subject:  Re: Quick question about choosing homing targets

Okay, the RotAngle is supposed to set the Rotangle, thus turning the crab in the direction of the target.
Is that not what its doing?

Author:  Asklar [ Sun Dec 23, 2012 12:20 am ]
Post subject:  Re: Quick question about choosing homing targets

Well, yeah. Do you see the body rotating?

Because if it's just moving to the right, there could be two problems; the RotAngle isn't changing at all, or it changes and returns to normal too fast, rotating the velocity to your right, or, you are not setting the angle properly.

I'm more inclined for the first one though, so instead of using self.RotAngle create any other variable and use it, then check if it works.

Author:  cyclops0000 [ Sun Dec 23, 2012 1:38 am ]
Post subject:  Re: Quick question about choosing homing targets

The body doesn't rotate at all, so I'm going to assume that it is not being set properly.

Author:  Asklar [ Sun Dec 23, 2012 1:46 am ]
Post subject:  Re: Quick question about choosing homing targets

Print the RotAngle before and after you make it change.

Author:  cyclops0000 [ Sun Dec 23, 2012 3:15 am ]
Post subject:  Re: Quick question about choosing homing targets

It says the Rotation is 0 when I press the F key, whichis the key that sends it flying, so it must not be tracking any enemies.


EDIT: I moved the rotation part to rotate as long as it exists, not just when the F key is pressed, and the crab stays standing straight the entire time, as if it were running a keep upright script. So the problem must be in the getting of the targets.

EDIT2: I also set it to print the name of its target, it is targeting itself.

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/