Data Realms Fan Forums http://45.55.195.193/ |
|
Help with proximity check on actors http://45.55.195.193/viewtopic.php?f=73&t=21422 |
Page 1 of 2 |
Author: | Dylanhutch [ Mon Feb 07, 2011 3:17 am ] |
Post subject: | 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 = ?. |
Author: | Abdul Alhazred [ Mon Feb 07, 2011 9:12 am ] |
Post subject: | 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 = ?. |
Author: | Coops [ Mon Feb 07, 2011 9:18 am ] |
Post subject: | 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.. |
Author: | Dylanhutch [ Mon Feb 07, 2011 10:11 am ] |
Post subject: | 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 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. |
Author: | none [ Mon Feb 07, 2011 10:39 am ] |
Post subject: | Re: Help with proximity check on actors |
What is the projectile? If its an actor you can set that in ini, Health = 1. |
Author: | Coops [ Mon Feb 07, 2011 10:40 am ] |
Post subject: | 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. |
Author: | Dylanhutch [ Mon Feb 07, 2011 11:09 am ] |
Post subject: | 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. |
Author: | none [ Mon Feb 07, 2011 2:33 pm ] |
Post subject: | 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. |
Author: | Dylanhutch [ Tue Feb 08, 2011 5:24 am ] |
Post subject: | 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. |
Author: | none [ Tue Feb 08, 2011 7:09 am ] |
Post subject: | 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. |
Author: | Dylanhutch [ Tue Feb 08, 2011 9:01 am ] |
Post subject: | 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. |
Author: | none [ Tue Feb 08, 2011 9:04 am ] |
Post subject: | 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 |
Author: | Dylanhutch [ Tue Feb 08, 2011 10:00 am ] |
Post subject: | 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: |
Author: | Coops [ Tue Feb 08, 2011 10:14 am ] |
Post subject: | Re: Help with proximity check on actors |
because the actor pointer in the SceneMan function is capitalized.. |
Author: | none [ Tue Feb 08, 2011 10:15 am ] |
Post subject: | Re: Help with proximity check on actors |
woops my bad Actor.Pos should be actor.Pos EDIT: Beat by the man.. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |