View unanswered posts | View active topics It is currently Fri Dec 27, 2024 9:22 am



Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
 Help with proximity check on actors 
Author Message
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Help with proximity check on actors
I want to make something happen to an object/actor when in range, I tried to use the homing rocket launcher script but it didn't seem to work at all.
This is the script I tried:

Code:
function Update(self)
    local curdist = 100;
    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
   actor.Example = 1
   end
   end
   end


Also, how would I make the same thing happen to the thing the script is attached to? I tried self.Example = ?.


Mon Feb 07, 2011 3:17 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Help with proximity check on actors
The homing missile code does not take wrapping maps in to account. Try using ShortestDistance instead, like this:
Code:
   for Act in MovableMan.Actors do
      if SceneMan:ShortestDistance(self.Pos, Act.Pos, false).Magnitude < 100 then
         print(Act) -- prints actor name and class to the console
      end
   end

Dylanhutch wrote:
Also, how would I make the same thing happen to the thing the script is attached to? I tried self.Example = ?.
I don't understand your question.


Mon Feb 07, 2011 9:12 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Help with proximity check on actors
I think he might be asking how to have whatever happens to the closest Actor that is found, also happen to the scripted object as well, Or vise versa..


Mon Feb 07, 2011 9:18 am
Profile
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Help with proximity check on actors
Abdul Alhazred wrote:
The homing missile code does not take wrapping maps in to account. Try using ShortestDistance instead, like this:
Code:
   for Act in MovableMan.Actors do
      if SceneMan:ShortestDistance(self.Pos, Act.Pos, false).Magnitude < 100 then
         print(Act) -- prints actor name and class to the console
      end
   end


So I Would put it after "print(Act)"?
Like
Code:
   for Act in MovableMan.Actors do
      if SceneMan:ShortestDistance(self.Pos, Act.Pos, false).Magnitude < 100 then
         print(Act) -- prints actor name and class to the console
         Act.Health = 1      //Health is just for an example.
      end
   end


Abdul Alhazred wrote:
Dylanhutch wrote:
Also, how would I make the same thing happen to the thing the script is attached to? I tried self.Example = ?.
I don't understand your question.


I meant, I tried to get the command to work only for the thing the script is attached to.
In this case I would want to set my projectile's Health to 1. I have tried what should work, self.Health but it doesn't work.

EDIT
I guess I didn't word that very well, Health is just an example.


Last edited by Dylanhutch on Mon Feb 07, 2011 11:10 am, edited 1 time in total.



Mon Feb 07, 2011 10:11 am
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post Re: Help with proximity check on actors
What is the projectile?

If its an actor you can set that in ini, Health = 1.


Mon Feb 07, 2011 10:39 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Help with proximity check on actors
Well first off, Giving an MO health wont really work out well unless its an actor..

Second, What are you trying to accomplish with giving your projectile health?

EDIT: Dammit none, beat me to the punch.


Mon Feb 07, 2011 10:40 am
Profile
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Help with proximity check on actors
You guys aren't very observant are you. :)

It was just an example, I said that in the code.


Mon Feb 07, 2011 11:09 am
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post Re: Help with proximity check on actors
self is a reference to the thing the script is attached to,

Code:
function Create(self)
     self.Health = 1;
end


is the same as ini
Health = 1

for an actor of course, as you can't set health for a particle.

so as you you put example

Code:
function Create(self)
     self.Example = ?
end


will effect the thing the script is attached to as long as self.Example is releated to the attached thing, e.g. self.Health won't work if its attached to a particle, just like self.BurstScale won't work if the script is attached to an actor.


Mon Feb 07, 2011 2:33 pm
Profile
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Help with proximity check on actors
Well, that worked but it just does it anyway and spams the console with the actor name that it is attached to.
I need it to not use itself, it's an actor.

I want to make an actor make other actors have thing happen to them.
Like for example.
I might want to make an actor die when in range of my actor.

I'll try some more things.
But help would be appreciated.


Tue Feb 08, 2011 5:24 am
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post Re: Help with proximity check on actors
Code:
function Update(self) -- Runs code every frame for self
     for actor in MovableMan.Actors do -- scrolls through list of actors, "actor" can be anything like bob: "for bob in MovableMan:Actors do" it's a reference
          if SceneMan:ShortestDistance(self.Pos, Actor.Pos, false).Magnitude < 100 then -- the distance between the youself and the actor "100" is the range
               actor.Health = 1; --  Any actor that is less that 100 pixels away from you will do this
          end -- ends the if statement
     end -- ends the for statement
end -- ends the function


Hope that clears things up.


Tue Feb 08, 2011 7:09 am
Profile
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Help with proximity check on actors
I already know that, I want something to happen to my actor (self) when an actor is close to it.


Tue Feb 08, 2011 9:01 am
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post Re: Help with proximity check on actors
Code:
function Update(self)
     for actor in MovableMan.Actors do
          if SceneMan:ShortestDistance(self.Pos, Actor.Pos, false).Magnitude < 100 then
               self.Health = 1;
          end
     end
end


Tue Feb 08, 2011 9:04 am
Profile
User avatar

Joined: Sun Apr 25, 2010 12:04 am
Posts: 303
Location: Australia
Reply with quote
Post Re: Help with proximity check on actors
Doesn't seem to work, I don't know why. I just spams something about pos in console.


I tried it on a coalition light to test it, but it didn't work:
Attachment:
Test.7z [3.07 KiB]
Downloaded 198 times


Tue Feb 08, 2011 10:00 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Help with proximity check on actors
because the actor pointer in the SceneMan function is capitalized..


Tue Feb 08, 2011 10:14 am
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post Re: Help with proximity check on actors
woops my bad

Actor.Pos

should be

actor.Pos

EDIT: Beat by the man..


Tue Feb 08, 2011 10:15 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 20 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.063s | 15 Queries | GZIP : Off ]