Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Bondematt
Jan 26, 2007

Not too stupid

the posted:

Do I use Transform.localScale to increase the size of a gameobject? I just want it to increase in size after a collision.

Yeah, that should work.

Megadrive posted:

I'm using ex2d with Unity to make a top-down twin stick shootem up and I'd like to know whether there's a way to use Unity's built-in Collider, Collision and Rigidbody and so on classes with my own logic to make a collision system or should I literally just roll my own using tutorials on GPWiki or something? My biggest issue is that while I know how to detection collisions between, say a circle and an AABB or whatever, I don't know to resolve collisions without using a while loop and checking collisions over and over and using a lot of computational power. Unfortunately there doesn't seem to be any obvious tutorials on the matter online.

You can likely tie in Unity's system to what you need, either using OnCollisionEnter or OnTriggerEnter just to detect when a collision occurs and do your work from there. OnCollisionEnter gives a lot more information, but will continue to apply Unity's collision system unless you disable it/take the reigns right away.

Adbot
ADBOT LOVES YOU

the
Jul 18, 2004

by Cowcaster

Bondematt posted:

Yeah, that should work.

Alright, I did it, however it's not behaving exactly as I want. I have:

JavaScript code:
function OnCollisionEnter (col : Collision)
{
    if(col.gameObject.name == "sphereRed")
    {
        Destroy(col.gameObject);
		transform.localScale += Vector3(1.1,1.1,1.1);
    }
}
However, what that's doing is increasing it by 1.1 of it's current size every time it hits a red sphere, when I really want it to just increase by 1.1 of it's original size. How do I do that? Is there some way I can read the values of it's original size and store them into a var that I call back later?

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
I don't know Unity, but by definition should't localScale be initialized to (1,1,1)? Therefore, you don't need to add 1.1, you need to set to 1.1. That is, localScale = Vector3(1.1, 1.1, 1.1).

If not, you could always store the original scale in an initialization script for the entity and always do your comparisons with that.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

the posted:

However, what that's doing is increasing it by 1.1 of it's current size every time it hits a red sphere, when I really want it to just increase by 1.1 of it's original size. How do I do that? Is there some way I can read the values of it's original size and store them into a var that I call back later?
Are you sure your description is what's actually happening? If you hit 8 red spheres, is your object more than 256 times its original height?

Your numbers and description just seem like you're probably misunderstanding your own problem. The simple question that would reveal if my guess is correct would be this: does the very first red sphere you touch have the effect you want it to?

the
Jul 18, 2004

by Cowcaster

roomforthetuna posted:

Are you sure your description is what's actually happening? If you hit 8 red spheres, is your object more than 256 times its original height?

Your numbers and description just seem like you're probably misunderstanding your own problem. The simple question that would reveal if my guess is correct would be this: does the very first red sphere you touch have the effect you want it to?

I have about 10 red spheres bouncing around in a room and one green sphere (with the script on it). With the way I had it, the sphere grows exponentially large and eventually glitches outside of the box once it hits everything because it's so huge.

I'm trying to simulate the two spheres just 'merging' and becoming one that's twice the size, so I've gone the easy route and just said "annihilate one of them and grow larger" instead of trying to joint them or something (which sounds very difficult).

And it's entirely possible I'm misunderstanding it. I've just logged about 20 hours total in this program so far so my knowledge isn't the best. Thank god this program has good documentation though.

edit: \/\/\/ And I tried changing the += to an =, but all it did was grow the green sphere once, and then every other collision it remained it's same size. So it looks like that wasn't the answer :/

the fucked around with this message at 19:59 on Jun 14, 2013

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Edit: nevermind, I read the original requirement incorrectly.

Orzo fucked around with this message at 20:10 on Jun 14, 2013

superh
Oct 10, 2007

Touching every treasure

the posted:

Alright, I did it, however it's not behaving exactly as I want. I have:

JavaScript code:
function OnCollisionEnter (col : Collision)
{
    if(col.gameObject.name == "sphereRed")
    {
        Destroy(col.gameObject);
		transform.localScale += Vector3(1.1,1.1,1.1);
    }
}
However, what that's doing is increasing it by 1.1 of it's current size every time it hits a red sphere, when I really want it to just increase by 1.1 of it's original size. How do I do that? Is there some way I can read the values of it's original size and store them into a var that I call back later?

Shouldn't it be -

JavaScript code:
function OnCollisionEnter (col : Collision)
{
    if(col.gameObject.name == "sphereRed")
    {
        Destroy(col.gameObject);
		transform.localScale += Vector3(.1,.1,.1);
    }
}
So it's growing by 1/10th of the original scale (1) each time, instead of adding 1 and 1/10th of it's scale every time?

the
Jul 18, 2004

by Cowcaster
I would think that would shrink it? Let me try and I'll get back to you.

edit: Yep, shrinked it to 10% of it's size.

I think I need to do what Orzo said, which is store the original size somehow and say "if on collision, increase by original size + 1" except, I don't know how to do that.

superh
Oct 10, 2007

Touching every treasure

the posted:

I would think that would shrink it? Let me try and I'll get back to you.

edit: Yep, shrinked it to 10% of it's size.

I think I need to do what Orzo said, which is store the original size somehow and say "if on collision, increase by original size + 1" except, I don't know how to do that.

Is it still set to "=" from before? Setting it = .1 would shrink it but setting it += .1 will add .1 to whatever's in there.


Keeping a reference to it's original size (new Vector(1,1,1)) then setting it to origin+new Vector(.1,.1,.1) will just grow it once too.

You could break it down to this though -

code:

	origin = new Vector(1,1,1);
	change = new Vector(0,0,0);

	// On collision
	change += new Vector(.1,.1,.1);
	transform.localScale = origin + change;
But that is pretty much the same as what I wrote before, just implemented a different way.

vvv Great! No problem! :D

superh fucked around with this message at 20:15 on Jun 14, 2013

the
Jul 18, 2004

by Cowcaster
By george, he's done it! :monocle:

Thanks, man

Edit: Now, my ideal situation would be if instead of destroying the gameobject, the two objects became joined at the point of collision, which would of course be more realistic. How difficult is that to accomplish?

the fucked around with this message at 20:18 on Jun 14, 2013

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

the posted:

I'm trying to simulate the two spheres just 'merging' and becoming one that's twice the size, so I've gone the easy route and just said "annihilate one of them and grow larger" instead of trying to joint them or something (which sounds very difficult).
How big is your original sphere compared to the box, measuring by height alone? Because unless it's very very small, you wouldn't have to eat everything to grow to the size of the box if it was actually doing what you said (growing exponentially, based on its new size).

I suspect you're actually getting the result you're asking for, that the sphere is growing by 1.1 original-sphere-diameters in each dimension every time it eats a sphere. The problem is just that this is much more growth than you expect - if your original sphere is a tenth of the height of the box then after eating nine spheres, it's filling the entire box. You probably would really want to grow the sphere by approximately the volume of the sphere it ate, not its diameter. This would be localScale+=Vector3(0.26,0.26,0.26) the first time, and even smaller each subsequent time.

the
Jul 18, 2004

by Cowcaster
I'm going to try to experiment with the sticking together (instead of destroying/growing) using this script. The guy wrote it in C# though, so I'll have to figure out how to translate to JS

edit: There are also some posts I've read where people suggest doing a contact normal force of 9.81 (gravity) on collision. A guy wrote this script which he claims works, but it's not for me:

JavaScript code:
//---------
// TRIGGER_MAGNETIC.JS
//
// Script used to enable magnetic mode,
//----------------------------

private var collisionNormal 	: Vector3;
var gravityStrength = 9.81;

private var contactAngle; 


//----------------------------
// OnCollision function 
// Acts as a trigger and calculates new gravity.
//----------------------------
function OnCollisionStay(collision : Collision) 
{
	for (var contact : ContactPoint in collision.contacts) 
	{
		Physics.gravity = contact.normal * gravityStrength;
	}
}



//----------------------------
// OnCOllisionExit function 
// Reset the gravity when the collider lost contact.
//----------------------------
function OnCollisionExit()
{
	Physics.gravity = Vector3(0, -9.81, 0);
}

the fucked around with this message at 21:11 on Jun 14, 2013

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Have you considered switching to C# yourself?

the
Jul 18, 2004

by Cowcaster

Orzo posted:

Have you considered switching to C# yourself?

I guess I could, I've never used it though. I've been learning Unity entirely through JS. The only other language I know is Python. I hear that Unity supports Python (boo, isn't it?) but I haven't explored that either.

xzzy
Mar 5, 2009

the posted:

I guess I could, I've never used it though. I've been learning Unity entirely through JS. The only other language I know is Python. I hear that Unity supports Python (boo, isn't it?) but I haven't explored that either.

C# isn't all that far off from JS.. it's mostly a few fairly simple alterations in syntax. It's pretty much the superior option for Unity so you'd do well in the long run to spend a weekend forcing yourself to learn it.

Even if all you do is port JS to C# it'll be instructive.

the
Jul 18, 2004

by Cowcaster
Well, I got it working. They stick together now, but it's completely unrealistic. There's no angular momentum (like if you collided with another object in space and stuck, you'd start to rotate as a system). Now to figure out how to give them realistic angular momentum.

ZorbaTHut
May 5, 2005

wake me when the world is saved
I've got a question whose answer is "no".

Is there any reasonably hardened and inexpensive MMO framework out there, suitable for indie games and with at least a small history of successful releases? I'm kind of looking for "Unity: MMO edition" or "UDK: MMO edition". Or even "Ogre3d: MMO edition".

Polio Vax Scene
Apr 5, 2009



What was that thing that Space Station 13 was made in again? That's probably as close as you'll get. I think that retro-looking online final fantasy-ish thing that floats around in Games was made in the same engine.

Ah, here we go, the engine is called BYOND. NEStalgia is the RPG I was thinking of. Certainly give it a shot if you're really devoted to this idea as it seemed pretty solid from my experiences with SS13 and NEStalgia.

Polio Vax Scene fucked around with this message at 22:27 on Jun 14, 2013

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

ZorbaTHut posted:

I've got a question whose answer is "no".

And thank god it is.

FuzzySlippers
Feb 6, 2009

I think you lose quite a lot by not switching to C# in Unity. I don't think Unityscript supports linq, extension methods, events, delegates, etc. I dunno about boo. I only had .net experience in VB.net before trying Unity and I picked it up easily and I'm also pretty programming dumb (literature major reporting in).

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!

the posted:

I guess I could, I've never used it though. I've been learning Unity entirely through JS. The only other language I know is Python. I hear that Unity supports Python (boo, isn't it?) but I haven't explored that either.
My strong opinion, and what seems to be a consensus among Unity developers (you've already run into the fact that most examples are in C#, and examples are critical to learning a new framework!) is that C# is the superior option.

It's also my opinion that using JavaScript where C# is an option is very very silly, considering how inferior of a language it is in any context where either can be run (i.e. not in a browser). Learn C#, it won't be a mistake.

ZorbaTHut
May 5, 2005

wake me when the world is saved

Manslaughter posted:

Ah, here we go, the engine is called BYOND. NEStalgia is the RPG I was thinking of. Certainly give it a shot if you're really devoted to this idea as it seemed pretty solid from my experiences with SS13 and NEStalgia.

Not gonna work for me, unfortunately, I'd need 3d support for this project :/ Ah well.

Polio Vax Scene
Apr 5, 2009



Agreeing with everyone else, learn C#. Before I knew C# I was elbow-deep in Javascript and happy with it, after I can't even look at a .js file without getting a bad taste in my mouth.

quote:

Not gonna work for me, unfortunately, I'd need 3d support for this project :/ Ah well.

Please let us know when you have a beta for Crimson Haze II available.

:cawg:

Polio Vax Scene fucked around with this message at 22:35 on Jun 14, 2013

Bondematt
Jan 26, 2007

Not too stupid

the posted:

Well, I got it working. They stick together now, but it's completely unrealistic. There's no angular momentum (like if you collided with another object in space and stuck, you'd start to rotate as a system). Now to figure out how to give them realistic angular momentum.

Are you following the parenting method? You need to re-add the momentum that the child force had during the collision. Using AddForceAtPosition at the position of the child in the direction of travel by using velocity * mass. You apply that to the parent rigidbody of course. It won't always spin as it may hit it just right to push it, but anything other than a direct shot should spin the new two sphere combo.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
So I've graduated to the cool kids club, I now work for Red Storm. :toot:

Suspicious Dish posted:

And thank god it is.
Eh, I dunno. I've seen enough examples that "MMOs" can exist with player counts as low as double-digits. I don't know if it'd actually be possible to build a viable business model on that though. Conceptually, you can make an MMO with as little as a client-server world system and a few minor centralized services (mainly transactions, inventory, and community), it's only when you start getting into seamless worlds and high load on the common services that things turn into an ungodly mess.

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

OneEightHundred posted:

Conceptually, you can make an MMO with as little as a client-server world system and a few minor centralized services (mainly transactions, inventory, and community)

Which is pretty much how they all were in the days before everquest; in the form of MUDs.

devilmouse
Mar 26, 2004

It's just like real life.

ZorbaTHut posted:

I've got a question whose answer is "no".

Is there any reasonably hardened and inexpensive MMO framework out there, suitable for indie games and with at least a small history of successful releases? I'm kind of looking for "Unity: MMO edition" or "UDK: MMO edition". Or even "Ogre3d: MMO edition".

The closest I can think of is: http://www.smartfoxserver.com/

It's probably still "room-based" so it's not super-fluid, but if you're comfortable with zoning people around, it should be ok enough for a My First MMO.

Hughlander
May 11, 2005

ZorbaTHut posted:

I've got a question whose answer is "no".

Is there any reasonably hardened and inexpensive MMO framework out there, suitable for indie games and with at least a small history of successful releases? I'm kind of looking for "Unity: MMO edition" or "UDK: MMO edition". Or even "Ogre3d: MMO edition".

Big Worlds is the closest I can think to that and apparently there's now even an Indie version. I know some heads down startups working on it but don't know of anything major to ever ship in the US with it.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
HTML5 question - I want to be able to make my game do the full-screen thing, but currently I'm using things like divs with scrollable overflow for some GUI elements - I gather I can go full screen with a container rather than just the canvas, but when I do so the layout gets screwed up (a float:right div ends up centered behind the canvas). Is the answer to this issue to just absolute-position everything within the full-screen container? I gather I'll have to rearrange and rescale it all anyway when it goes full screen, since otherwise the canvas element just ends up the same size as it always was.

Bonus question - can a canvas element be set up so it scales itself? ie. if I want the canvas to have its internal dimensions as 500x500, the area that I draw on, but render out to a 1000x1000 area. I realize I could do this by rendering to an off-screen canvas and then rendering that canvas onto the on-screen larger canvas, but can it be done more directly?

Winkle-Daddy
Mar 10, 2007
Cross posting from the python thread, because, let's face it, you guys know more about working with game engines, and I always get more complete answers here. I have a really odd problem.

I have come across an issue, and I'm not sure if the problem is in the python, or if it's in the game engine I'm using (pyglet). I decided to write my own text engine instead of using the built in methods available in pyglet.

I've got this in main.py:
Python code:
if __name__ == '__main__':
	textItems = []
	game_intro = text_object(text='Game Title',xpos=50,ypos=90,batch=GLOBAL_BATCH,fontsheet=GLOBAL_FONTSHEET,group=GTG)
	game_intro.toggleVisible(1)
	game_intro.timeBomb(10)
	textItems.append(game_intro)
	b = text_object(text='Some More Text',xpos=10,ypos=10,batch=GLOBAL_BATCH,fontsheet=GLOBAL_FONTSHEET,group=GTG)
	b.toggleVisible(1)
	b.timeBomb(30)
	textItems.append(b)
	pyglet.app.run()
Update function:
Python code:
def update(dt):
	for x in textItems:
		x.update(dt)
So, I have a "text_object" class which basically creates a sprite for each letter in the "text" argument and returns it back. So, I created a "timeBomb" method so that I can delete the object after x number of frame updates, where x is the argument provided.

Here is the relevant portion of the text_object class:
Python code:
	def timeBomb(self,frames):
		self.timeBombTrue = 1
		self.explodeDelay = frames
		self.explodeCount = 0

	def update(self,dt):
		if(self.timeBombTrue == 1):
			if(self.explodeCount < self.explodeDelay):
				self.explodeCount = self.explodeCount+1
			elif(self.explodeCount >= self.explodeDelay):
				self.destroyFree
	def destroyFree(self):
		for x in self.text_objects:
			x.delete()
So, when I try this, I get an error that NoneType object has no attribute delete. The weird thing is, if I go back to main.py and use only a single text object it works perfect. When I add the second text object, the second one needing to be destroyed throws that error. I decided to use a try statement there instead and do:

Python code:
	def destroyFree(self):
		for x in self.text_objects:
			try:
				x.delete()
			except:
				print(x)
Which results in:

code:
<pyglet.sprite.Sprite object at 0x269a610>
<pyglet.sprite.Sprite object at 0x269a750>
<pyglet.sprite.Sprite object at 0x269a890>
<pyglet.sprite.Sprite object at 0x269a9d0>
<pyglet.sprite.Sprite object at 0x269ab10>
<pyglet.sprite.Sprite object at 0x269ac50>
<pyglet.sprite.Sprite object at 0x269ad90>
<pyglet.sprite.Sprite object at 0x269afd0>
<pyglet.sprite.Sprite object at 0x269c0d0>
<pyglet.sprite.Sprite object at 0x269c210>
<pyglet.sprite.Sprite object at 0x269c350>
Any clue why my object seems to get hosed up when I add a second one? Or what I can do to try to track the problem down further?

the
Jul 18, 2004

by Cowcaster
I'm thinking to get a more realistic collision between two spheres I could do a force to the normal of the collision.

Should I use Forcemode.force or Constantforce?

Also, this may be a difficult question, but do you know of a way I could program in actual physics, i.e. Newton's law of universal gravitation giving each sphere a gravitational acceleration towards the others? I'm not sure if there's a way to say "sense every other gameobject, calculate the distance between it, and accelerate towards it at this rate."

the fucked around with this message at 20:31 on Jun 15, 2013

Max Facetime
Apr 18, 2009

roomforthetuna posted:

HTML5 question - I want to be able to make my game do the full-screen thing, but currently I'm using things like divs with scrollable overflow for some GUI elements - I gather I can go full screen with a container rather than just the canvas, but when I do so the layout gets screwed up (a float:right div ends up centered behind the canvas). Is the answer to this issue to just absolute-position everything within the full-screen container? I gather I'll have to rearrange and rescale it all anyway when it goes full screen, since otherwise the canvas element just ends up the same size as it always was.

A radical suggestion: just make the webpage scale to any resolution. One major operating system already ships with a browser that's permanently in full-screen mode. "Going full-screen" is meaningless in such a situation. You could do browser sniffing and give instructions on how to toggle full-screen mode in each major browser instead.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Max Facetime posted:

A radical suggestion: just make the webpage scale to any resolution. One major operating system already ships with a browser that's permanently in full-screen mode. "Going full-screen" is meaningless in such a situation. You could do browser sniffing and give instructions on how to toggle full-screen mode in each major browser instead.
Doesn't work because the game embeds in Facebook, where the browser being full screen is not at all similar to the game being full screen. (And it makes all the measuring-to-auto-scale a pain in the arse too.)

I probably will end up doing 'manual' absolute positioning of everything based on the detected space though, because I'd like the game to work on mobile devices - arranging stuff differently for a different aspect ratio seems like a good idea too.

roomforthetuna fucked around with this message at 23:00 on Jun 15, 2013

SupSuper
Apr 8, 2009

At the Heart of the city is an Alien horror, so vile and so powerful that not even death can claim it.
What's the general solution for collaborating with Unity? All I've tried is import/export on a shared project and it's not... great. Optimally I would like it to just integrate with a VCS but from what I've found, that's Pro only?

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

SupSuper posted:

What's the general solution for collaborating with Unity? All I've tried is import/export on a shared project and it's not... great. Optimally I would like it to just integrate with a VCS but from what I've found, that's Pro only?

Go into edit...project setings...editor and make sure it's set to meta files. Only put the Assets and Project Settings folders in the VCS, everything else unity can generate/regenerate on the fly.

http://forum.unity3d.com/threads/141420-Unity-and-Git

FuzzySlippers
Feb 6, 2009

Merging constant big changes to a project is difficult, but if you are only working with code I found it easier to transfer the project folder as a zip and then just push / pull code changes. Here's my hgi ignore if it's helpful.

Tres Burritos
Sep 3, 2009

So yet again I am dicking around with OpenGL and I've run into something weird. I can make some vertices and color them with VBOs.

displaying the VBOs:

code:
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, VBH.vbo);
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
gl.glColorPointer(3, GL.GL_FLOAT, VBH.vertexStride, VBH.colorPointer);
gl.glVertexPointer(3, GL.GL_FLOAT, VBH.vertexStride, VBH.vertexPointer);
gl.glDrawArrays(GL.GL_[s]TRIANGLES[/s], 0, 36);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL2.GL_COLOR_ARRAY);
The problem happens when I move the camera, the vertices go from looking like this



to this



I have nooooo idea what's going on. all of the "duplicates" flash as well.

all I'm doing is calling this code before the upper stuff.

code:
//camera bidness
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
			
//perspective
float widthHeightRatio = (float)canvas.getWidth() / (float) canvas.getHeight();
glu.gluPerspective([s]ViewingAngle[/s], widthHeightRatio, MinimumRenderDistance, MaximumRenderDistance);
glu.gluLookAt(X_Position, Y_Position, Z_Position, X_Target, Y_Target, Z_Target, X_Is_Up, Y_Is_Up, Z_Is_Up);
			
//change back
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
You're not calling gl.glClear.

Tres Burritos
Sep 3, 2009

Orzo posted:

You're not calling gl.glClear.

Gaaaaahhh so stupid. Thanks.

Adbot
ADBOT LOVES YOU

Woodsy Owl
Oct 27, 2004

the posted:

Also, this may be a difficult question, but do you know of a way I could program in actual physics, i.e. Newton's law of universal gravitation giving each sphere a gravitational acceleration towards the others? I'm not sure if there's a way to say "sense every other gameobject, calculate the distance between it, and accelerate towards it at this rate."

This isn't too difficult. Iterate through each object and compare it to every other object. Calculate the x and y components of the force of gravity and determine the direction(signs) if the forces. Then add the acceleration components to the base acceleration vector for the object.

An iterator nested inside another iterator works well. However, this method is O(n^2) so performance blows if you have a bunch of objects to gravitate towards each other. Remember that the universal gravitational constant is really small so the force of gravity is really weak.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply