Author |
Message |
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Follow
Okay. I have an MOPixel that's sposed to find thenearest actor and follow it, but whenever i try it, CC tells me the value is nil. Like "self.Pos = self.parent.Pos" says parent is nil, but i have it in create.
Thanks
|
Tue Jun 09, 2009 1:17 am |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Follow
I need to see the create code.
|
Tue Jun 09, 2009 1:29 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Follow
Code: function Create(self) local curdist = 15; for actor in MovableMan.Actors do local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist then curdist = dist; self.parent = actor self.parent.Team = self.Team end end end
|
Tue Jun 09, 2009 1:36 am |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Follow
Problem 1: Code: self.parent.Team = self.Team
Problem 2 is that curdist might be to low.
|
Tue Jun 09, 2009 1:49 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Follow
So what do i change it to?
|
Tue Jun 09, 2009 5:30 am |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Follow
How fast is the pixel being fired?
|
Tue Jun 09, 2009 5:53 am |
|
|
piipu
Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
|
Re: Follow
Change curdist to at least 50. Change the line quoted by mail to Code: self.Team = self.parent.Team That should fix it.
|
Tue Jun 09, 2009 8:11 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Follow
What about self.Pos = self.parent.Pos? I need it in update as well.
|
Tue Jun 09, 2009 7:08 pm |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Follow
How about just making the MOPixel home in on the parent actor. Like a missile. Or, is that what you are doing?
|
Tue Jun 09, 2009 7:10 pm |
|
|
zalo
Joined: Sat Feb 03, 2007 7:11 pm Posts: 1496
|
Re: Follow
How about you just use my example?
One of the drawbacks though is that there can only be one. Though, that's easily fixable.
Attachments:
File comment: All you have to do is pick it up, and it starts giving you health.
TestShield.rte.rar [2.24 KiB]
Downloaded 211 times
|
Wed Jun 10, 2009 12:36 am |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Follow
Zalo does it again it!
|
Wed Jun 10, 2009 6:31 am |
|
|
|