View unanswered posts | View active topics It is currently Thu Sep 19, 2019 2:12 pm



Reply to topic  [ 11 posts ] 
 Spawning multiple MOPixels and having multiple math.randoms 
Author Message
Data Realms SUPER Elite
Data Realms SUPER Elite

Joined: Thu Jun 03, 2010 10:06 pm
Posts: 3717
Location: Over there.
Reply with quote
Post Spawning multiple MOPixels and having multiple math.randoms
So, I've been waiting here doing nothing, just surfing the net, and then I realized I could be wasting my time more efficiently by doing some modding. My problem is is that I want to make multiple MOPixels randomly around a single point () but I don't want to have to make, like, twenty of what is basically the same script.

Here

Code:
      particle = CreateMOPixel("Particle");
      particle.Pos = self.THISISAPOINTINSPACE - Vector(math.random(-15,15),math.random(-15,15))
      for i=0, 15 ,1 do
         MovableMan:AddMO(particle);
      end


So, I want 15 particles to form a circular shape around the point, but I don't want to have to define it 15 times with different names and such, because this is a heavily condensed version of this code.

How would I be able to do this, as I know that math.random will only happen once and all the points will either make an error (I don't know if my for i=0 bla bla bla is correct) or they will all spawn in the same place.


Sun Aug 14, 2011 8:38 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
If you place all the particle definition inside the for?

I made a code which makes 10 rockets spawn and it works:
Code:
                for G = 1, 10 do
                        self.ExplosiveDamage = CreateAEmitter("Particle Beast Rocket")
                        self.ExplosiveDamage.Pos = self.MuzzlePos
                      self.ExplosiveDamage:SetWhichMOToNotHit(MovableMan:GetMOFromID(self.RootID),-1)
                        self.ExplosiveDamage.Vel = Vector((25+(G*math.random(2)))*self.reverseNum,math.random(5)-(G/2)):RadRotate(self.RotAngle)
                        MovableMan:AddParticle(self.ExplosiveDamage)
         end


Then you just need to change the position to make it circle a point, like making a vector and rotate acording to the G (in your script the i) value.


Sun Aug 14, 2011 8:48 pm
Profile
Data Realms SUPER Elite
Data Realms SUPER Elite

Joined: Thu Jun 03, 2010 10:06 pm
Posts: 3717
Location: Over there.
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
I have that figured already. Thanks brah.


Sun Aug 14, 2011 8:50 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
You are welcome.


Sun Aug 14, 2011 8:51 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7093
Location: b8bbd5
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
I dunno if that means you figured it out entirely or not, but in case you haven't, use math.sin and math.cos.
Code:
particle.Pos = Vector(math.sin(math.random(-math.pi, math.pi)) * (radius) + (pointx), math.cos(math.random(-math.pi, math.pi)) * (radius) + (pointy))

Insert values or variables for pointx, pointy, and radius. Also check my parens, I might have messed them up. Also you might need to swap sin and cos, I can never remember if the x coord uses sin or cos.
EDIT: Oh, and this goes in your for loop, as does everything when defining your particle. Each runthrough of the for should define a new particle, define it's position, then add it to MovableMan.


Mon Aug 15, 2011 5:05 pm
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: Spawning multiple MOPixels and having multiple math.randoms
If I'm reading this right, you want several MOPixels to spawn at a point in a circular formation?

How come I never see people do something like this?

Code:
self.pixel.Pos = self.yourpoint.Pos + Vector(your diameter,0):RadRotate(math.rad(math.random(360)))


Mon Aug 15, 2011 6:10 pm
Profile
Data Realms SUPER Elite
Data Realms SUPER Elite

Joined: Thu Jun 03, 2010 10:06 pm
Posts: 3717
Location: Over there.
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
Because I'm not doing it either. It's more like an explosion in reverse, not a moving circle. It was just a little test so I could ask this question. If you want some of my new and improved laser scripts, I can hand 'em over. They're fantastic. And creds to you, Duh, for actually posting your blue laser cannon in the MMDump, it's what I've based it off of.

This was a laser rifle, in which at the point that the ObstacleRay hits a rough circle of MOPs collapse into itself, it's pretty damn neat for a test, I may keep it. But if you want to use it or something, just ask, it's a mod for the benefit of the people.

As you know, you can never have too many lasers, unless they're bad lasers. That is why I am trying to get everybody to use my extremely simple laser format. It works ♥♥♥♥.*

*That's a real word, you know.


Mon Aug 15, 2011 8:30 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
Coops, that works, but replace the "360" with "math.pi * 2". You're rotating in radians, not degrees.


Mon Aug 15, 2011 10:35 pm
Profile WWW
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
The description for math.rad is:

Code:
Converts a number from degrees to radians.


I figured converting 360 degrees to radians is the same thing.


Mon Aug 15, 2011 11:10 pm
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3134
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
Oh, whoops, I missed the math.rad. Probably easier to just give it 2 * math.pi instead of converting it, though.


Mon Aug 15, 2011 11:35 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Spawning multiple MOPixels and having multiple math.randoms
RadRotate(math.random() * (2*math.pi));

works great


Mon Aug 15, 2011 11:37 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.020s | 13 Queries | GZIP : Off ]