Author |
Message |
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Projectile detection?
Is there anyway, through lua script, to check to see if there is a non-actor object, like a projectile (MOPixel, MOSRotating/AEmitter), near a position?
I'm trying to write a script for barrier that stops projectiles in mid-air. When a projectile enters the barrier's spherical field, its velocity begins to decrease until it reaches zero (or in this case, a zero vector). At first, I tried using SceneMan:CastMORay()'s to search around the barrier's center, doing a ray cast every pi/12 radians up to 2pi. Through testing, I found this method worked for actors but not projectiles.
So is there a way to know whether or not a projectile has entered the barrier's field?
|
Tue Jun 09, 2009 2:37 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Projectile detection?
for particle in MovableMan.Particles
if particle.Pos
That's how you iterate through the list, though it's going to be laggy.
|
Tue Jun 09, 2009 2:43 am |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
Re: Projectile detection?
Ninja'd by Grif again.
You can reduce the lag somewhat by using a rectangular search area, but it won't look too nice if you make a square field.
|
Tue Jun 09, 2009 2:43 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: Projectile detection?
Thanks Grif.
It seems MovableMan has a lot of child variables that arn't documented. What other MovableMan.<something>'s are there that don't appear in the Lua docs?
|
Tue Jun 09, 2009 3:09 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Projectile detection?
MovableMan.Particles, Actors, and Devices should be everything. I think.
|
Tue Jun 09, 2009 3:12 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Projectile detection?
i think its MovableMan.Items actually.. for easy near-ness detection you can use Code: (self.Pos - particle.Pos).Magnitude < radius , which is better and faster than square boxes.
Last edited by Geti on Tue Jun 09, 2009 9:51 pm, edited 1 time in total.
|
Tue Jun 09, 2009 3:15 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: Projectile detection?
Woo! Got it working =D.
|
Tue Jun 09, 2009 4:19 am |
|
|
zalo
Joined: Sat Feb 03, 2007 7:11 pm Posts: 1496
|
Re: Projectile detection?
It's funny that you had thought of that.
I'd thought of it some time in May, but left it because it was kind of laggy.
You can have it if you want to look at it as an example.
|
Tue Jun 09, 2009 5:15 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: Projectile detection?
To cut down on lag, I delayed the for loop in the update to every 10ms with a timer, and reset the timer every time the if statement has passed. Worked pretty well. Also, you'll want to exclude any particles with the preset name "None".
|
Tue Jun 09, 2009 9:39 pm |
|
|
|