Data Realms Fan Forums
http://forums.datarealms.com/

Spawning multiple MOPixels and having multiple math.randoms
http://forums.datarealms.com/viewtopic.php?f=73&t=25160
Page 1 of 1

Author:  Nonsequitorian [ Sun Aug 14, 2011 8:38 pm ]
Post subject:  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.

Author:  Asklar [ Sun Aug 14, 2011 8:48 pm ]
Post subject:  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.

Author:  Nonsequitorian [ Sun Aug 14, 2011 8:50 pm ]
Post subject:  Re: Spawning multiple MOPixels and having multiple math.randoms

I have that figured already. Thanks brah.

Author:  Asklar [ Sun Aug 14, 2011 8:51 pm ]
Post subject:  Re: Spawning multiple MOPixels and having multiple math.randoms

You are welcome.

Author:  Duh102 [ Mon Aug 15, 2011 5:05 pm ]
Post subject:  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.

Author:  Coops [ Mon Aug 15, 2011 6:10 pm ]
Post subject:  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)))

Author:  Nonsequitorian [ Mon Aug 15, 2011 8:30 pm ]
Post subject:  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.

Author:  TheLastBanana [ Mon Aug 15, 2011 10:35 pm ]
Post subject:  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.

Author:  Coops [ Mon Aug 15, 2011 11:10 pm ]
Post subject:  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.

Author:  TheLastBanana [ Mon Aug 15, 2011 11:35 pm ]
Post subject:  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.

Author:  Grif [ Mon Aug 15, 2011 11:37 pm ]
Post subject:  Re: Spawning multiple MOPixels and having multiple math.randoms

RadRotate(math.random() * (2*math.pi));

works great

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/