title: 3D camera implementation

text:
# Question
Title: 3D camera implementation
I've been bashing my head against the concept of a 'camera' for my 3D world for some time now, and I'm not sure I'm doing this right anymore. Maybe I've been working on this for too long and have confused myself, or I have a fundamental mis-understanding of the topic. Therefor, I could use a refresher/help on the concept of a 3D camera object and how that is supposed to operate. I have a camera class with a position, an orientation (quaternion), and a derived transformation matrix. Currently, my draw loop looks something like this:

```
Start Frame
Mult current matrix with matrix: Camera.Transform.Inverse
Save current matrix
Render all objects
Restore matrix
End Frame

```

However, this makes the camera's position reflected about the origin (ie, the camera's position vector has negative values but DRAWS as if it had positive values) and modification of position and rotation are consequently negated from their expected values (to get closer to the origin from z=3, I must add...).

So here is my issue: am I using this correctly? How is a camera supposed to work? Say I want to billboard something, how would I use the camera's information to do this?

Additionally, the clipping plane suddenly cuts out my scene if I rotate too far in any direction and I'm not sure why. How can I fix/avoid this using camera information? Any help is much appreciated!

# Answer
> 3 votes
I see that you doesn't mention projection matrix in your code. Multiplication must go in this order: world * view * projection. Another order could work for special cases but they are not correct.

Position and orientation is not enough for view matrix. You have to specify UP vector.

Are you using some framework like Directx/opengl? Both of them contains lookAt function. If not, find specification and implement it by yourself. Here is directx implementation: http://msdn.microsoft.com/en-us/library/bb281710(v=VS.85).aspx.

Also double check if you are using same left handed or right handed coordinate system for all of your matrices.

# Answer
> 1 votes
Are you clear on the inversing process? From a math standpoint, i mean.

If you were to manipulate a world space Matrix to represent the camera orientation and position, the matrix you send to the effect is the inverse of that. *An inverted a matrix is not simply the result of negation of its components*. There is more to it mathematically, even more than transposing. It seems like you probably already know this, and you may be using a framework method for inversing, but just making sure.

Typically, I store and manipulate a world space quat & position, which I visualize as a real world movie camera, bundle them into a world space Matrix, then invert that matrix *properly* and send the result off to the effect.

I use the world space version's component vectors for any needed local space transformations. Typically these values are different than simply negated inverted version's values.

---
Tags: 3d, graphics-programming, rendering, camera
---


# Question
Title: Is there a way to keep the mesh collider when updating objects in Unity?
I have a 3D object as an imported asset in Unity which i want to make updates to in Maya. The asset get's updated automatically in Unity when i save the object in Maya - but not in the project hierarchy where i have placed it in the scene.

Is there a way to keep the object with it's mesh collider when the model is updated without having to re-create it in the hierarchy for every iteration?

# Answer
> 1 votes
I'm not 100% sure on what you're asking, but here are two suggestions anyway:

1) Have you made a prefab of this object in the scene? Hopefully if you update the model, the prefab gets updated, so the object in the scene gets updated.

2) If that isn't what you want, you could try writing an editor script to do things for you. Look here: http://unity3d.com/support/documentation/ScriptReference/AssetPostprocessor.OnPostprocessModel.html

---
Tags: 3d, unity
---


# Question
Title: Is it possible to import UV-maps in Unity3D without manually importing the associated texture?
When i import an object from Maya with a defined UV-map i have to manually import the texture (image) and assign it to the material.

Is there a way to keep the materials texture reference from Maya when importing into Unity?

# Answer
I think if the textures its looking for are in a folder called /Textures/ somewhere in the asset view, and named the same as whatever you're calling it in Maya, it'll "just work".

http://unity3d.com/support/documentation/Components/class-Mesh.html
> 1 votes

---
Tags: unity, textures
---


title: What should audio programmers know?

text:
# Question
Title: What should audio programmers know?
I'm a music composition student also getting a minor-plus-some in computer science. I love writing music and making sound effects and want to write music for games. But, I also realize everyone and their mother wants to do that. With that in mind, and since I'm already equally in love with programming, I'm interested in looking at focusing some aspects of the computer science portion of my education towards audio implementation for games.

What I've done/am doing:

* Wrote "MusicManager" classes that are aware of musical timings and a small amount of automated mixing based on game events
* Reading Who is Fourier? as I work my way toward understanding Fourier analysis and implementing the FFT
* Learning FMOD Designer and using the designer API in a game (of course not taking a class specifically on this, I'm good for learning APIs on my own)

With that background, I've got a two-part question.

So aside from the things I list above, and the good ole fundamentals of computer science (data structures and algorithms, discrete math, OO/structured design), what are studios looking for in audio programmers?

Also, G.A.N.G. and Audio Engineering Society lecturers speak as though audio programmers are the next hot thing in games, but do many studios even have or think to hire dedicated audio programmers?

# Answer
> G.A.N.G. and AES lecturers speak as though audio programmers are the next hot thing in games

I had to Google for those terms - you might want to edit your question to be clearer about what those names mean, because I doubt most will have heard of them. Needless to say, they are bound to be a bit biased regarding their own relevance.

> do many studios even have or think to hire dedicated audio programmers?

No.

Some do. Most probably don't.

As far as I can tell, most people are using a typical audio library, often with a thin wrapper around it, and getting their resident sound/music guy to create sounds for the game via Wwise, FMod Designer, or similar, and that's about it.

A small but growing number of games have had complex or novel audio requirements of late, eg. since the Guitar Hero thing took off. But despite good sales of those products, it's still just a drop in the ocean in terms of the quantity of games that require such features and the number of developers attempting them.
> 8 votes

# Answer
> I love writing music and making sound effects and want to write music for games. But, I also realize everyone and their mother wants to do that.

Since when? Audio in games has never really been the focal point of the industry, and that is not changing. There are companies that want wonderful soundtracks and some good sound effects (naturally), but they use audio libraries and hire people to make that content in a 3rd party context.

Audio programmers are not really hired by the game company.
> 0 votes

---
Tags: software-engineering, audio
---


title: What is today's target platform?

text:
# Question
Title: What is today's target platform?
The question came randomly and I think it will really help to know from everyone's experience.

It all started from this article on gamedev.net http://www.gamedev.net/reference/programming/features/x64ErrCol/ and then I saw a couple of more tweets embracing the 64-bit architectures.

So to you what is today's target platform and what important advantages does it have?

# Answer
The genre that the entire game industry seems to be most "atwitter" over is the **casual games** market. I think it's largely due to the success of games like Bejeweled and Peggle, combined with all the Facebook games and recognizing that the audience of Facebook games are people with a lot of time on their hands but very little desire to play a typical hard core or skills-based game.

If you acknowledge that the casual games genre is the popular one today, then it follows that **"today's target platform" is the browser**. Flash is still extremely popular, Java applets not so much, and some Facebook games can be simple HTML.

Browser games are typically the most compatible and require **zero installation for users** (given the user has the Flash plugin in the case of Flash games). They're not terribly difficult to write from a game developer's standpoint, since **you can often avoid the game loop** (especially, again, in the casual game genre) and simply respond to user input, like a traditional business app. And with upcoming technologies like HTML5 and WebGL, they can still have **decent graphics** and other capabilities.
> 15 votes

# Answer
Check out Valve's Hardware Survey. It will tell you most of what you will need to know about the PC game market at least
> 12 votes

# Answer
Your target platform should be whatever the people you want to play your game, own.

There's no point targeting high-end PCs if you're making a game for the kinds of people that are happy with their ancient P4 running W2K.
> 6 votes

# Answer
64-bit architectures are great if you have a game that can take advantage of 64-bit architectures. If your budget doesn't have at least eight figures you probably don't have that game.

Target the system that makes the most sense for your game. That's probably a 32-bit build, and if it isn't, you likely already know it isn't.
> 2 votes

# Answer
Today's target platform is... all of them! Or at least several of them.

If you're making games commercially... you really want support as many platforms (and therefore as many potential customers) as possible/practical given the requirements of the game.
> 1 votes

# Answer
My target platforms are Facebook, Flash, the browser generally, also Windows PCs, Macs, and Linux, and that's just for one project. The physical hardware is next to irrelevant for me.
> 1 votes

# Answer
I think of the marget as segmented into a few tiers. At one end, you have the browser and smartphone market, which would be Flash, iOS, and Android. These involve a small target group of hardware, and typically provide one or few central locations where your content will be placed. (Flash can go anywhere, but there are some major hubs that are a good target for flash games)

Next up is the casual/indie market, which bleeds a little bit into the smartphone market, but in addition adds Xbox Live / XNA, Playstation Network, Unity 3d, and Steam for PC. While Steam is not exactly a platform, it is a fully featured service that feels fairly close to Xbox live in terms of digital distribution and user accounts. These are also singular 'shops' where all associated content for the platform can be found, thus making it easier for someone to find your game. Unity gives you the ability to distribute across a wide range of platforms, including the PC, the browser, iPhone, and Android.

Finally you have the AAA traditional game platforms which consists of PS3, Xbox 360, Wii, and the PC. These are the hardest to target and most likely involve larger budgets and contracts. Also designing a non-casual PC game complicates matters as you have many hardware targets you want your game to run on.
> 1 votes

# Answer
A 1 GHz Pentium III with 512 MB ram and a GeForce FX 5200. If the game runs reasonably on this platform then it should run smoothly on almost every PC in the wild.

It's easy to add in optional graphical effects, high resolution textures and so on that users with better computers can enable, it's not so easy to get a game already designed for high end PCs running reasonably on lesser hardware.
> 1 votes

---
Tags: architecture, platform
---


# Question
Title: How far can you get with Garry's Mod and no money?
My sixth-grader is very interested in FPS game development but I don't think he has grasped the magnitude of the task ahead. He is a Halo fan and so his current goal is to make a similar game but better. Heh. I am not going to discourage him though.

I gave him a Steam account and by himself he has discovered Garry's Mod and installed tortoise svn to add packs (and play them). He has also downloaded and poked around in the UDK and trials of Visual C++ and SoftImage. When I say "by himself" I mean he has asked his online buddies for advice and suggestions, and he has watched countless Youtube "how-to" videos (the classroom of the future).

Although I am a programmer my expertise does not lie in games. I am having a hard time understanding what Garry's Mod encompasses. How far can he get with it and what additional tools should I help him to get?

# Answer
Garry's Mod is a mod of the Halflife 2 engine. You can make your own mods of the Halflife 2 engine using the Halflife 2 SDK, or you can try to modify Garry's Mod through scripts. I don't think you're allowed to modify the source code to garry's mod.

If he wanted to really make his own "halo" type FPS from scratch, then what he'll want to do is work with the source engine, the halflife2 SDK. This is totally free if you own ANY source game (so you probably already have it, since you have garry's mod on steam). This will provide you with a bunch of C++ projects which wrap the source engine and allow you to do really ANYTHING you want with it. Tons and tons of AAA commercial games and indie games with everything from RTS to RPG to FPS are made using the source engine. Its extremely flexible.

That said, it is going to be EXTREMELY hard for your young son to get involved in. How strong are his programming concepts? He's going to have to be ROCK SOLID on C++ in order to start writing his own game / mod using the source engine.

So, if that sounds way too daunting for him (For a sixth grader, I can't imagine one kid being able to get anywhere writing their own video game from scratch, realistically. Old games like mario and mortal kombat had small development teams, he could TRY to write a 2D game from scratch like that, but its still going to be HARD. Those games took like 10 programmers with degrees a year to write. He isn't that qualified and there is just one of him. Modern, 3D, AAA games require teams of 20-50 programmers and billions of dollars. EDIT: okay, millions, I exaggerate. Even if you were the greatest programmer in the world, it would take you forever to write a blockbuster game by yourself. Practically impossible for anyone.)

Then instead maybe try just little mutations rather than a full conversion mod. You could try using the lua scripting that Garry's Mod supports in order to make small changes to the gameplay, maybe add a new item or a new feature. I haven't played around with Garry's Mod's scripting so I can't talk from experience like I can about the source engine.

You mentioned the UDK, which is pretty cool, but again, thats like taking the source engine and starting from scratch. It takes forever, and its REALLY hard.

The way I got started when I was first programming (and this was in 9th-10th grade, mind you) I wrote mutations for Unreal Tournament. They have their own language (unrealscript) but its pretty readable and pretty high level (it reads like java more or less) and the cool thing is Epic has always had tons of support for mods and mutations in Unreal Tournament. So, you could start just writing a mutation that makes rockets go faster, or rockets go slower, and then you can hop in Unreal Tournament and play your mutation. That way, you can start small. If you try to code a whole mod from scratch as your first experience, trust me, you'll never get past concept.

Hope that wasn't too demoralizing. I think its awesome your son is passionate about gaming at such a young age! (He installed Tortoise SVN on his own, and he's seriously in the 6th grade? This kid is a future software developer for sure!). But kids certainly don't understand how much work goes into building their favorite games, and being able to write your own Halo is a pipedream.

I'd say start with simpler things. Have him write pong, and then space invaders. Then go to Unreal Tournament and write some mutations, and when he's good with mutations, then you can think about mods.

And as far as tools, I did my first UnrealTournament mutations in Wordpad! No joke! Its pretty easy, you write it up, you save it, and then you use command line to compile it using the tools that are already provided with UT by Epic Games.

If you're going to work with the source engine, you'll need visual studio. You can probably get away with visual studio express fine, but you may have to download the windows SDK as well if you get the express version. Other than that, just tons of patience, and good programming fundamentals. :)
> 16 votes

# Answer
I highly recommend that you/he check out Unity3D. It's a fantastic game engine with a visual world editor and some solid scripting options. It has a great community and it's totally free to use for indie development.

Garry's Mod is great if he wants to just learn and play around, especially with FPS stuff, but I'm pretty sure you can't make commercial games with it (although I don't know if that's even your son's goal).
> 13 votes

# Answer
When I was around your son's age (13 or so), the thing that first got me into game development was a program called Klik n Play. It was a program that allowed you to make simple 2d games without any coding at all by using a point and click action/reaction Event Editor to "program" it. It no longer exists, but I believe its descendant, Multimedia Fusion (http://www.clickteam.com/eng/mmf2.php), is still supported and available, which boasts a similar low barrier to entry, requiring no programming. The down side to these programs is that the end result might be less than inspiring, as it's pretty much limited to relatively simple 2d games.

Alternatively, I would also highly recommend Unity (http://unity3d.com/), which has some great tutorials, and is similar in functionality to UDK but in my opinion much easier. The pluses are that your son will be able to quickly create some pretty impressive 3d games (and 2d as well), though the minus would be that there is some (relatively little) programming involved. Again, it's easier than UDK, but with similar results. The programming options include Javascript, C# and Boo. As I mentioned, there are some incredible (at least two of which are like 80+ pdfs teaching you how to do a lot of cool stuff) tutorials on their website, which made it a breeze for me personally to learn, although my disclaimer is that I started using Unity having already been programming professionally for several years, which might bias me (easier than UDK though!).

Unity is free. Multimedia Fusion is like $100.
> 7 votes

# Answer
Mods for Garry's Mod are written entirely in Lua. If he can get a hang of Lua, and learning Garry's Mod API which is really well documented on that Wiki...I think he could get pretty far. He can use the 3d models, maps, and sounds that come with the game, and just start out buy just scripting different weapons and move to more advanced stuff like game objectives as he get's more comfortable.
> 6 votes

# Answer
I think that there is nothing better to start your games/computer graphics programming than XNA. That is not engine but just library with tons of useful functions and classes. Also allows you to very easily port your game to xbox. There are limitations if you want to make something big, but thats not your sons case for next few years:). My first game was written in it and it opened me door to greater programming in real directx&opengl.

I also recommend to not try to make 3D game for the first try. 2D games are much easier. And doesnt need too much math because you can imagine or draw everything to paper. If your son wants to start programming in 3D. I would recommend him to start study linear algebra, thats what you need in 3D everyday.

Also I wanna encourage him to do it. I was little boy who wanted to make game too. I sticked to that dream and now i am working in movie industry programming renderer for real movies. I can't imagine better job. Computer graphics are so much fun to work with. Same for artists and engineers.
> 4 votes

# Answer
As far as Garry's Mod goes, I'd probably place it on a level similar to that of Game Maker for use. You can do Lua scripting, and I have played some very nice mods with it (my favourite was called Trouble In Terrorist Town, which played like Call of Duty mixed with Murder In The Dark).

However, it did remind me of the time I played with Unity 3D. To get further, I would probably say Unity3D like Matt Rix has, just because of the resemblance to GMod that it has - most of the action is in the WYSIWYG window, but because the scripting plays a larger part, the customizability is greater too.
> 1 votes

---
Tags: tools
---


# Question
Title: 2D Side Scrolling game and "walk over ground" collision detection
The question is not hard, I'm writing a game engine for 2D side scrolling games, however I'm thinking to my 2D side scrolling game and I always come up with the problem of "how should I do collision with the ground". I think I couldn't handle the collision with ground (ground for me is "where the player walk", so something heavily used) in a per-pixel way, and I can't even do it with simple shape comparison (because the ground can be tilted), so what's the correct way? I'know what tiles are and i've read about it, but how much should be big each tile to not appear like a stairs?Are there any other approach?

I watched this game and is very nice how he walks on ground: http://www.youtube.com/watch?v=DmSAQwbbig8&feature=player\_embedded

If there are "platforms" in mid air, how should I handle them?I can walk over them but I can't pass "inside". Imagine a platform in mid air, it allows you to walk over it but limit you because you can't jump in the area she fits

*Sorry for my english, it's not my native language and this topic has a lot of keywords I don't know so I have to use workarounds Thanks for any answer*

**Additional informations and suggestions:** I'm doing a game course in this period and I asked them how to do this, they suggested me this approach (a QuadTree): -All map is divided into "big nodes" -Each bigger node has sub nodes, to find where the player is -You can find player's node with a ray on player position -When you find the node where the player is, you can do collision check through all pixels (which can be 100-200px nothing more)

Here is an example, however i didn't show very well the bigger nodes because i'm not very good with photoshop :P

How is this approach?

# Answer
> 8 votes
Typically the way I've handled this in the past is by creating metadata for your level that is nothing more than a series of ordered points to define line segments, and doing player collision vs. line segment collision on them. For a tile based game you only have to author data for those tiles. This is better than trying to do pixel tests since it's easy to define how things interact with lines than a series of pixels.

Then it's a simple matter of defining how you want your collision on your character to be. Circles are the easiest. Usually you probably want to do something like a pill shape, though (two circles and a rectangle).

Basically it's a simplified form of the idea of a collision model that a lot of 3D games use, except it's just lines.

# Answer
> 8 votes
It doesn't necessarily deal with floating platforms and jumping, but consider the idea of walkable areas as opposed to walkable surfaces. For example here's a forest with a sloping path. You only want the player walking on the light dirt path.

Now have an invisible bound area that defines the places the player can walk. Here's what it might look like overlaid on the forest path. It would NOT be rendered in the actual game of course.

Then you put your player in the picture, and only allow their origin point (probably base of their feet) to be inside the walk zone.

This would work pretty well if you let the player click on any spot, and if it was in the walk zone they would walk to that spot.

Game Maker allows you to do something like this.

# Answer
> 1 votes
Your question is a bit broad, it seems to hint that you are not perfectly comfortable with the programming and/or mathematics involved.

What I describe here is what I after long consideration believe to be easiest for you to understand and implement:

Your world is split into a series of relatively narrow vertical stripes, something like 20 pixels wide each. For each stripe you define a number of lines stretching from one side of the stripe to the other, these lines should be placed to match the surface of the ground in that given area.

Imagine your character represented as two vertical line pieces, one stretching from the top of the character and approximately 75% down, the other from the bottom and approximately 75% up, so they overlap on the middle.

In order to do collision detection you first determine in what stripe the player is located, then you determine the exact vertical position of each line of that stripe at the players exact horizontal location, then you determine if any of the two lines representing the player overlap any of the stripe lines. If only the lower part of the player overlap anything then there is a collision with the ground, and the player needs to be moved up accordingly, if only the upper part of the player overlap something then there is a collision with the roof, and the player needs to be moved down. If both parts collide, or if the moving up or down cause the other part to collide, then there is a horizontal collision and the player must be moved back where he came from.

It's hard stuff to mess with if you are not a skilled mathematician, but I hope you can use it. I'm afraid it doesn't get a lot easier unless you resort to something block based.

---
Tags: 2d, collision-detection, side-scroller
---


# Question
Title: Any Open Source Games That Can Be Ported to Android?
I'm looking for some other open source games out there that I can port (easily or not) to Android. I know that it's possible to port Wolfenstein and Doom and was wondering if there are any others out there. I was thinking of Civilization (I remember a linux port some time back) and a few others. It can be in C/C++ or Java. Thanks in advance.

# Answer
> 4 votes
Your best bet is probably cube. It uses the zlib license. It's been ported to pretty small platforms so running on an android device isn't out of the question.

---
Tags: c++, android, open-source
---


# Question
Title: 2D Game dev and Java. Other possibilities than OpenGL?
I recently started to program some basic OpenGL stuff in Java, but OpenGL and DirectX is too much to handle and to understand for me and I'm getting bored really fast.

Now I am wondering if there are other possibilities than OpenGL (or DirectX) to make simple 2D graphics and to get started in Game Development, even if its limited. I will probably use OpenGL anyway when I am more experienced.

# Answer
> 13 votes
There is also the library Slick which provides the most common features for developing 2D games (images, animations, sounds, gameloop...). It has the advantage over the Java 2D library to be more specific to video games as it includes collisions checking and a physics engine.

# Answer
> 9 votes
Of course! Java has a built in Java 2D library which requires no OpenGL or DirectX knowledge, and I highly recommend starting with it! In fact, it has pretty okay performance.

The essential starting point is to define your own class which extends Frame (or Applet), and then override the `paint(Graphics g)` method and use `g` to draw to the screen.

# Answer
> 3 votes
Why don't you simply use Swing or Awt for a start (for 2D)? If you correclty design your game (I mean, a well though MVC design), you will be able to upgrage your game with a better game display engine later. The main goal, if you're working alone, is to quickly achieve to have something displayed on the screen, is'nt it ? It boosts your enthusiasm ...

# Answer
> 3 votes
Not exactly intended for games, but Processing is quite popular for 2D canvas graphics, it might be interesting to check.

# Answer
> 2 votes
Try basic canvas libraries if you are looking to develop just 2D games. I actually learn't to use 2D canvas by building a game on it right about the time this question was posted :) Now I am graduating to webGL.

---
Tags: 2d, java
---


# Question
Title: Integration my application with Facebook
So I recently developed this game which I would like to launch into Facebook but am having a hard time figuring out how on earth do I get the basics right. Like extracting user data i.e friends playing the game. Compile a global leader board and such. Also I was wondering if I want to keep a live update on who has got the highest score on the leader board, how do I go about doing that!?

Any suggestions and links to material explaining Facebook application integration for dummies will be a great help! Thanks...

# Answer
I guess you probably know about the Facebook API Documentation. Other than that you can find various snippets and examples via Google but a lot of them still target the old Facebook API. Personally I found the API-Docs and the code-examples to be sufficient to get started, but this might vary depending on the programming-language you're going to use.

Typically you would create a server application that provides the leaderboard and live-updates to your client apps. The server-app uses the Facebook API to get user data from Facebook.

To get user data (like friends etc.) the user needs to grant your application permission to that data. You can find more information about authentication here: http://developers.facebook.com/docs/authentication/

**Update:** These links might also help you getting started. They target the iPhone, but should give you an overview nevertheless: Using the FB Graph API, Getting the users profile
> 5 votes

# Answer
This page has some basic functionality explained with PHP server side. Most likely you want to rewrite those PHP scripts as they seem to be open for SQL-injections.

http://ideveloper.kodingen.com/2010/facebook-friends-leaderboard/
> 1 votes

---
Tags: facebook, leaderboards
---


# Question
Title: I'm trying to learn the "digital physics" required to do a floating network of spheres
If that is even what it is called. What I am trying to do it: http://asterisq.com/products/constellation/roamer/demo

Can someone please point me to towards a book or in vaguely the right direction? I don't even know where to start or what physics/maths to read about?

# Answer
> 3 votes
What you're looking at is called a force-directed graph. Google for that and you should find some helpful documentation. The math is surprisingly straightforward.

# Answer
> 3 votes
Vector maths is a must, you shouldn't need more than the basic parts for this, but the rest is generally very recommendable for a game programmer, so if you skip the cool stuff for now be sure to get back on the topic sometime. From there you could read about ragdoll physics, though a lot of sources for that may be "heavier" than what you need, so I'll just sketch out how I presume the animation works.

It runs a set number of updates per second.
For every update it iterate over all pairs of objects.
If the objects are too close each of the two objects will be moved a little away the other.
If they are connected and too far from one another each object will be moved a little closer to the other.
In both cases, the more the distance is off, the more they should move. Try for instance moving the objects 1/10 of what they are are off the target.
It's probably best to not move the objects immediately when you do the calculation, but rather for each object sum the movement over an entire update and execute it only after the movement relative to all the other objects has been calculated.

Note:
This setup does not use velocity and acceleration as one would with common ragdoll physics, that is on purpose since the goal is to spread the nodes out nicely rather than simulate real physics.

---
Tags: mathematics, physics
---


title: Algorithm for determining random events

text:
# Question
Title: Algorithm for determining random events
I'm struggling with coming up with an elegant solution to generating random events in the game that I'm working on.

Say there are 4 classes of events that can happen, with varying events in those classes that may occur.

So something along the lines of

```
main_events = {"common event", "not so common event", "somewhat rare event", "rare event"}
sub_events[0] = {"common event 1", "common event 2",..}
...

```

I have a somewhat kludgey solution in place that first just has a random number generated between 0 and 100, and if the number falls within a given range then a main event will be triggered. Then I'll do another random roll to see which sub event occurs.

Is there a better solution than something along these lines? Like I mention, it doesn't feel very elegant, and I'd like to make it easily expandable for the addition of future events.

# Answer
> 23 votes
(This is based on my answer for a similar question on Stack Overflow.)

It sounds like you're asking for a more flexible way of specifying the probability of each event. For that, you can use a simple weighing algorithm: simply decide how common each event should be and assign it a weight that is appropriate compared to the other weights. For example, if you have events A, B and C, with probabilities 70%, 25% and 5%, you could give them the weights 70, 25 and 5 (or 14, 5, and 1 - the important thing is the relative difference).

Once you have that, you can use the following algorithm to select an event:

Given a list L of items (I,W), where I is the item and W is the weight:

1. Add all of the weights together. Call this sum S.
2. Generate a random number between 0 and S (excluding S, but including 0). Call this value R.
3. Initialize a variable to 0 to keep track of the running total. We'll call this T.
4. For each item (I,W) in L:
    1. T=T+W
    2. If T \> R, return I.

It's up to you if you want to first select between the different groups of events, or if you want a single table with all of the events (where each "group" has an appropriate sum compared to the others).

# Answer
> 5 votes
Michael's solution is perfect if you want a single table of possible events.

Let's say you want to build a random insult generator, though. In this case, a series of tables would work best. You'd start with a table that has a list of general patterns. For example,

```
Your [RELATIVE] [RELATION] [ANIMAL]!
Go [VERB] [NOUN] in your [ORIFICE]!

```

Now say the random generator picks the second pattern. You call the verb table, which has entries like:

```
stick
jam
shove

```

But here's where it gets interesting, your noun table might look like

```
[ANIMAL]
your [RELATIVE]
[ADJECTIVE] [NOUN]

```

So you see, in this manner you can generate sophisticated and complex results.

As for actually implementing something like this, here's an example of how you might do it in JavaScript.

```
function Noun() {
    var items = 3;
    var i = Math.floor(Math.random()*items);
    switch (i)
        case 0:
            return Animal();
            break;
        case 1:
            return "your " + Relative();
            break;
        case 2:
            return Adjective() + Noun();
            break;
}

```

Obviously this is a crude example (you might generate, for example, "Go shove flaming your mom in your eye socket!"), but it's meant more as an illustration, since I don't think I explained it very well...

# Answer
> 3 votes
My answer to a question on generating random drops may very well work for this too.

---
Tags: game-design, algorithm, random, events
---


title: Maya 3D model to iOS OpenGL ES

text:
# Question
Title: Maya 3D model to iOS OpenGL ES
I need to display, rotate, and zoom a 3D model in OpenGL ES (iPhone/iPad). The 3D graphic artists are using Maya (on OS/X). What export format should I be looking at to use their 3D models in the app?

Also, a number of Maya plug-ins don't work on the Mac (apparently it doesn't handle plug-ins the same way as Windows and Linux), so I may need an external tool to handle the conversion.

I'm still learning my way around the 3D dev-world, so any advice is appreciated.

Thanks!

# Answer
One thing to know about OpenGL is that it doesn't have native model loaders. That is, there is no glLoadModel() function or similar. Instead, you must either use an existing loader that converts the coords into something OpenGL can read. It doesn't really matter what you use as a format, but .obj is probably the simplest and most popular to go with.

The wavefront .obj loader
> 4 votes

# Answer
It seems like you:

> You can pick a format you want to support then write a loader for the model.

I found a forum page where someone wrote an .obj loader.

http://www.iphonedevsdk.com/forum/iphone-sdk-game-development/4696-working-maya-models-iphone.html
> 2 votes

# Answer
As others suggested, the `obj` format might be a way to go. It doesn't support bones or animations though.

Another option is COLLADA. Since this is an XML file you should be able to parse and extract information from it easily. Here's a blog post that sheds some light on this.

Writing a good/robust parser for COLLADA won't be easy though. My biggest gripe with COLLADA is, that the generated files from different applications (eg. a COLLADA file exported with Blender and one exported with Maya) can be quite different.

Depending on how many features you need, it could also be advisable to compile a parser like COLLADA DOM for iOS (maybe it has been done already).
> 0 votes

---
Tags: 3d, opengl-es, ipad
---


title: Unity3D, how much code do you write?

text:
# Question
Title: Unity3D, how much code do you write?
I'm curious to know the workflow when creating a game in Unity3D?

Does it generate a lot of code for you?

My understanding is that you describe the game in Unity and do scripting on the back end to do the logic. Kind of like you use Unity to describe the puppets and you use a scripting language as the puppet master.

# Answer
Unity3D consists of a game engine plus a (fairly rudimentary) 3D editor. It provides meshes, textures, shaders, terrain, cameras, animations, particle systems, audio samples, and other kinds of object that are useful in video games. It includes PHYSX (a proprietary physics engine owned by Nvidia), and Mono (the open source implementation of the Common Language Runtime, aka .NET).

How much of this you use is up to you. You can represent all your data structures as Unity objects, build your world in Unity's editor, turn on the physics, and let events take their course, with a minimum of scripting. Alternatively, you could turn off the physics engine, construct your world algorithmically, and explicitly program all the behaviour and physics of the objects.

You can choose to program behaviour entirely in Mono (using one of the languages C#, JavaScript, or Boo), or you can write it in another language and link it with your Unity project. (The actual integration with the game objects must be via Mono, but this can be a fairly thin layer if you like.)

The workflow is much the same as with any game engine. Artists make models and textures and animations, audio specialists make the sounds, programmers write shaders and behaviour.

The community of Unity programmers is very helpful, both at answers.unity3d.com and forum.unity3d.com. (And maybe here at Stack Exchange?)

The best way to find out is to try it out: the basic version is free, and you get a 30-day trial period for the "Pro" version.
> 18 votes

# Answer
Unity3D is more of a wrapper/library than a 'drag and drop' game engine. It doesn't generate code nor does it come with 'off-the-shelf' scripts.

For example, Unreal has a default first person camera, character controller, collision detection and AI.

You have none of that in Unity3D. What you get from Unity3D is a game loop, component-based entity system, a comprehensive math library, means to load media, handling of meshes, camera, immediate mode GUI, shaders, rendering pipeline and other low level functionality. Plus a nice editor. You just have to worry about high level functionality. For example, you still have to code your own first person camera (if you are not using the default one). However, you do not need to deal with calculating the look-at vectors and such.

Unity3D doesn't generate any code for your game, strictly (It does generate code for running your game, to be more accurate, but none for your gameplay)

You will have to use the API to define your game. You can look at the examples that come with Unity3D and re-uses those code; there are a couple of pre-defined scripts, but usually you have to customize those to meet your needs.

You create the game through scripting; you write scripts for behaviours, design the level in Unity3D, and assign those behaviours to entities (or game-objects). It's very flexible, but it still requires effort to write a game. I would compare it to Flash for 3D.
> 6 votes

# Answer
The surface of Unity3D looks like it's super easy, and nearly everything is pre-build, but none of that is true. If you ignore to use already existing scripts (which exists for every engine, bad point against Unity) and plugins that you describe as somewhat ultra mighty, what they are definitely not, Unity is just an programming interface with editor.

You have most of the code by your own. I experienced that in 2 different projects.
> 3 votes

# Answer
The analogy with flash is quite right, but I don't really understand your analogy with puppets.

The good things about unity are:

* cross-platform: That's a very big plus, I would say the bigger reason.
* High-quality engine and implementation, I mean using Unity gameobjects etc.
* Very easy to make a simple game from scratch, so that's a plus for making prototypes.

The bad things:

* Can't link with C++ or C, so your project might only work on Unity. With C# one might argues that it will work on XNA, but C++ would have been nice. With this remark I mean that it is not a tool that veteran professionals or autodidacts would use, since you don't have a total control on your application, but this doesn't mean there are thing you can't do with Unity. On the other hand, a team with a great idea and talented artists can do awesome stuff without needing experienced programmers.
* It's quite new, so obviously no-one knows where this tool will lead.

The thing I don't like with Unity is that it feels like all the hard work is done, so programmers are much less valuable. On the other hand it's great for quickly teaching people how to build things fast.

So to conclude: Unity (or tool like Unity) is more for artists who can't reach out to great programmers, but can still know to do a little game scripting. OF COURSE you can make a full featured game, add realistic IA, doing a mmo net-code and what not, but big companies would not use Unity.

Programming models allows one to propose a solution that suits 3/4 of development tools so that it fits to those "independents" game makers. It values one particular tool and it also values artists, but not programmers (except the ones from the unity team, of course).

Unity is a good shortcut for non-programmers, but they have to understand that video games come from lines of code, and that you can't do everything just with an awesome tool. At some point it requires to know something about low-level programming.

Having a personal project in mind, I would not use Unity, because I don't like C# or Boo (Panda is good with python, so why bother with a commercial software ?), and because if I show my project and it's done with unity, it will be much less impressive.
> 2 votes

# Answer
Unity requires you to script, but without all the boilerplates. In a typical OpenGL game, you will need to initialize the matrices and cameras like crazy. In Unity, you create a script to tell the behavior of something, then attach it to an object to make it behave.
> 1 votes

# Answer
If by generate a lot of code for you , you would include pre-built functions that you can use to make your life easy regarding collision detection and rotation calculations (Library) then yes, it takes a lot of coding out of the picture and gives you optimized versions at hand and ready to go. Mostly functions that you will need specifically for Game Development in all builds.

It may sound redundant to say this , but in my experience , when Unity3D isn't busy crashing or building it's making my life easy by letting me change whatever I want and leave the Quaternion based math to the people that have a master degree in mathematics and still trust me enough to le me change whatever I want.

It will write nothing for you, rather help you out in the way it thinks is best and let you write whatever you want.

In one word, Flexible
> 1 votes

---
Tags: unity
---


# Question
Title: What languages are used to develop MMORPGs like EVE Online and WOW?
As I understand it, MMORPGs are games that run on your computer like any other normal 3d video game but, with each action that happens with in the game, changes are made to the universe via HTTP calls to the server. So the players computer does all the heavy lifting in terms of rendering the graphics and animations but, web frameworks do the online communication.

* So I am wondering what web frameworks, web servers and databases are being used to create MMORPGs like EVE Online and W.O.W.?
* Also, what programming languages and 3d game engines are being used to make the client side (3d graphics/animation/sounds) part of the game?

# Answer
> 31 votes
Most companies use C++. Eve is an outlier, the core graphics engine is in C++, while the game logic is, as others have noted, in Python. CCP also makes a lot of contributions to Stackless itself, which is in C for the most part. WoW is C++ for the game itself, though the UI is scripted in Lua. Cryptic (Champions Online, Star Trek Online) uses plain C, but that it is somewhat rare in the industry. Java pops up every now and then, ex. Runescape, but I can't think of anything AAA. Disney has used Panda3D (a Python-based engine written in C) for a number of their MMOs, but as with Eve thats uncommon.

Overall it seems like C++ for the game logic and engine, with Lua for client scripting is the closest you will find to a standard.

As for the web side, it is all over. We (Cryptic) use a mix of PHP, C, and Python (Django) for various bits. CCP uses ASP for the website itself, and Python to power the backend (slowly drifting together though). WAR and LOTRO both use PHP for their site, though it isn't clear what particular frameworks they are using (if any).

You mentioned that MMOs work via web API calls though, which isn't the case. An HTTP-based protocol would be far too inefficient, and HTTP is not designed for long-running connections. Pretty much all MMOs (that aren't web based like Kingdom of Loathing or Urban Dead) use custom servers and custom protocols. The clients are highly stateful, doing something like bringing up an inventory UI isn't going to fire off a request to the server since all that information is cached on the client.

# Answer
> 6 votes
A few links for EVE Online:

Basically, EVE Online runs on SQL Server 2005 and some other Microsoft software. The client backbone is mostly written in Python however (Stackless Python to be exact, from what I can remember) and some C++ most likely.

As for World of Warcraft, I do know they use Lua for all of the client GUI stuff, but aside from that I don't think they use Lua for anything else. C++ is likely what is used. WoW, I would think also uses some Windows boxes but it seems likely that they would have some other types of boxes specific to certain tasks that may not be Windows-based at all.

Not a lot of info, but hope it helps.

A lot of these games seperate servers based on functionality, so they would have a database server that is only responsible for storing objects/whatever and the servers that actually run the game world (validate player actions, etc.).

# Answer
> 3 votes
I'm not quite sure about EVE and WoW, but I've seen MMO games use C++, C#, Java and even PHP for server (the latter only for simple browser-based games, though).

Client is most often written in C++ (or Flash if it's a browser-based game); I've worked with a .NET-based client once (C# mixed with C++/CLI).

And almost always some kind of dynamic scripting language is used to facilitate developing "designer" content - e.g. abilities, quests, etc - things that change often, and can be changed by game designers as opposed to programmers.

# Answer
> 3 votes
First, MMORPGs or any online game does not use HTTP or "web frameworks" in the first place.

A server is programmed just like the game itself, in C++, and communication is achieved by using sockets to transmit packet over the network.

Servers often run another OS, and include only game code, so a lot of player can play on a single server smoothly.

I don't know how blizzard manages their servers, I don't know if they use clusters or not.

Of course when I say "sockets" and "C++", I'm talking about the real time game, not other services the game might offer, like the armory with WoW for example. They might just use a database which can be read from multiple services, like the forum, the armory, the game, the account administration etc, but my thought is that they have dependent databases, which seeks for new entries etc, so everything can sync up nicely.

I think the guy in charge of the network part of WoW might be a real badass.

# Answer
> 1 votes
For EVE, they gave a talk about StacklessIO on PyCon 2009: http://us.pycon.org/2009/conference/schedule/event/91/

# Answer
> 0 votes
There are dozens of game engines out there. The two that pop into my mind are Unreal engine and Source.

As for languages, that depends on the task. The rendering and other performance critical parts are usually done in one of native languages. C++ for example. But it is common to use some dynamic language to define scripts because this code is more likely to change and is often written by less 'hardcore' programmers :-) Lua, Python, Ruby - they all can be used here.

# Answer
> 0 votes
WoW uses Lua for all their internal scripting as well. I'm not sure if they modified the language itself, but I wouldn't doubt it so it could suit their needs. You can bet they have different tools that make it easy for their designers to modify/tweak scripts. This is insider information from friends of mine that are/used to be WoW devs.

---
Tags: mmo, server
---


# Question
Title: Self-righting agents that have fallen over
I need insect-like agents that have fallen/rolled on their back/side to naturally re-orient themselves. The agents are modeled as simple cuboids in the physics engine (Bullet) to approximate an ant-like shape.

At the moment I correct the orientation by instantly altering it when the dot product of surface 'up' and agent 'up' is less than some number (e.g. -0.5). Thus the agents can fall over only so much before they are insta-righted in the blink of an eye.

Obviously this looks nasty. Plus in the border cases, where the dot product isn't quite low enough, they can still fall over and don't get self-righted.

So, I need a way to have the critters automatically roll back onto their feet. How can I do this? The way I see it there are two problems:

1) How to determine the best rotation axis (e.g. better to roll on their back than head-to-tail)?

2) How to work out the magnitude of torque required to overcome the physics engine, whilst not being too much that has them flipping end over end?

\[Full disclosure: I originally posted this question on gamedev.net, to no response. I also posted in StackOverflow, but deleted the post when this stackexchange was recommended instead\]

# Answer
> 6 votes
My feeling is it would be easier to fake it than do it with full physics. If your bugs can be animated, give them an animation of leaping up in the air, rotating, then landing.

You know that sooner or later any physics based method is going to be (heh) buggy. Bug on a slope, object in its way, etc.

# Answer
> 5 votes
You should do some kind of rotation impulse.

Probably sideways is the easiest to flip over, so have it either flip over to the right or left, but choose randomly each time.

As for figuring out how much power is needed for the impulse, just test it out. Start it low and keep bumping it till it works correctly. Then figure out the min and max power to flip over correctly. Randomly select one of those when you need to flip.

To make it a bit more realistic, set a small timer between when the object knows its upside down, wait, and when when its time to flip, check if it is still upside down, if so, then flip.

---
Tags: c++, 3d, mathematics, physics, character
---


# Question
Title: Should larger Unity Projects use Visual Studio
I've worked with several engines and I'm most comfortable with a mature engine, world editor and C++ codebase.

I'm now looking at Unity as a side-project and have mostly been working in Javascript.

Has anyone done a large scale project with Unity and does it require Visual Studio or is sticking to the Javascript approach best?

Are there any big pitfalls with large scale Unity projects or with working with Visual Studio?

Most the stuff I've seen has been focused at smaller Indies or people with little experience.

**I should have phrased this as an external IDE, Visual Studio is just my IDE of choice**

# Answer
Depends what you mean by "require Visual Studio". Your choice of IDE isn't really related to the language used or size of the project, in my opinion, just so long as you're using an editor you feel comfortable with.

If you are looking for editors other than the default Scite that comes with Unity...

If you feel like changing from Javascript to C# or Boo, I find Monodevelop to be very excellent. There are some other suggestions here.

**Updated for question update**

Absolutely, use an external IDE or text editor. It's all just text files in the end, Unity doesn't offer any additional benefit from using Scite. Pick (or find) an editor you love and use that, it can only possibly make your life better (even on small projects!)
> 6 votes

# Answer
Visual Studio's primary "benefit" is its project management, build system, integrated debugger, plugins and extensions, and so on. Most of those are not going to work well with Unity, especially a Unity program primarily in JavaScript. The basic editor will still work fine, but Visual Studio is kind of crap at editing compared to things whose main purpose is to edit text, like vim and Emacs.

If your goal is a well-integrated and consistent deployment to your developers, you should probably just use Unity's built-in editor. It's not great, but it's fast, free, and works everywhere.

On the other hand, if your developers have a lot of Visual Studio experience, they can use that if they want. It's just going to be as a text editor, and not as a project manager or compiler or debugger (except for the odd Unity native extension).
> 5 votes

# Answer
As Unity is highly cross platform, I suspect that there is no requirement to use Visual Studio. You should use whatever development tools you're comfortable with. I've learned Vim over the past year and can't recommend it highly enough as an editor. Presumably any code build you would need to do could be accomplished on the command line.
> 1 votes

# Answer
You should probably stick with MonoDevelop. It's not as polished as visual studio but is the only debugger you're going to be able to use with Unity 3.

Personally I use Visual Studio Professional when I'm on Windows, and all of our projects stick to C# exclusively. It's a great IDE and the C# integration (read: autocomplete) is pretty good.
> 1 votes

# Answer
I have been using Monodevelop and VS2010 for Unity game development for several months now. MD seems to let me have breakpoints and some minor control but it's all silver lining only, you can only do a play or an edit when you run normally outside mono debug run call.

VS2010 just refuses to synch at all, I couldn't figure out yet how to get the same execution, I'm guessing it's not supported.

Monodevelop needs some getting used to, both for JS and C# I reckon. Going from C++ to JS you probably must be wondering if you are coding or doodling with a crayon by now.

Just do yourself a big favor and go to the preferences for keybindings and change it all to the ones you are used to. Hitting CTRL-SHIFT-HOME for a backwards indent on a keyboard requiring FN left arrow is a whopping 4 key combo. Even mortal combat was easier to learn than that.

In short: VS2010, possible but no feedback or breakpoints, Monodevelop, takes some getting used to but it 500 times better than unitron/uniscite , that's just plain notepad--
> 1 votes

---
Tags: unity, ide
---


# Question
Title: Spriting engine on mobile platforms, OpenGLES
I'm writing a basic spriting engine for a blackberry app, and I want to know the best way to draw tons of sprites using the `glDrawArrays()` command.

We have several sprites that move around the screen, and a bunch of sprites for background tiles. Zelda-1 like tiling.

My first idea was to create a quad at the origin for every sprite that exists and `glTranslatef` it to wherever it needs to be. But several hundred sprites to draw per frame, you only get to call this once for every call to `glDrawArrays()` so its not a good idea to call `glTranslatef()` on each sprite as you draw it. That's the reason `glVertex3f()` was left out..

So I'm left with the option of maintaining a master vertex array and every time a sprite moves in the game, pushing the update to move the 4 vertices that represent its quad in the MASTERVERTEXARRAY. I don't like this but it seems my only option.

What I'd really like is to be able to somehow create an array of "translation values" to use for every quad that gets drawn..

```
glTranslateArray( ... ) ;

```

But alas, no such thing exists.

# Answer
> 3 votes
I'm working on iPhone and Android but OpenGL ES is the same. So on mobile Platform (and Destop too), you must use DrawCalls carefully. I try to use \< 50 to render a scene.

For my sprite engine on OpenGL ES 1.x, i use an unique coordinates system for the rendering function. So for each sprite and at each frame, i compute its positions in this coordinates system. That's a lot of operations for CPU but i can use one glDrawElement for all sprites using the same texture.

I have two categories of sprite:

* Transparent sprites: i use a qsort
* Solid sprites: no sort just ZBuffer

With good texture atlases, i use 10 drawcalls (glDrawElement) for my 500 sprites and have a good framerate.

Ps: for OpenGL ES 2.x, i use the gpu to do translation in the Vertex shader.

---
Tags: java, opengl-es
---


# Question
Title: How do I animate a custom ability with a continuous beam in Starcraft 2?
I'm building an ability that drains energy from the target unit and gives it to caster unit. I've tried to associate an actor that hooks in to the ability's start event to create the continuous beam, but the beam never appears. What's the right way to do this?

# Answer
> 1 votes
Check out "DominationBeam" under actors. I think this is an ability that a campaign character could use that had a beam going from her to the target. You'll need to have events creating the actor when the effect of the ability starts and destroying the actor when the effect ends. Don't use the ability's start/end in the events, just the effect that is triggered by the ability.

The Host Impact fields are the ones where you will probably want it to use the scope "Scope Target" and the subject as "\_Unit". Same with the Host Launch, except the scope is the caster. In the impact/launch attachment fields you'll need to put what points the beams should attach to.

---
Tags: starcraft-2
---


title: Should Game Gui APIs use themes?

text:
# Question
Title: Should Game Gui APIs use themes?
I'm making a GUI API (in C++) for games which uses Allegro 5 as a backend. I looked at how GuiChan works and noticed that they intend for the user to override the paint event and do all the drawing yourself.

Since I felt that in general, there's a decent standard to how widgets behave, I have a static theme class in each widget class (static ButtonTheme buttonTheme; etc) and the parameters set in that theme are used to construct that widget (from there, the parameters can be changed individually for specific widgets). These sorts of things are: padding, font color, border color, is drawing border, back color, size, min / max size etc).

Where I also differ from GuiChan is in the fact that instead of default drawing being rectangles, the widgets have bitmap pointers and if they are NULL, it draws rectangles like GuiChan, if not, they are drawn with bitmaps: ex: button has default, hover, clicked. And if hover is not provided, the switch case will just use default for hover. Each theme has corresponding bitmaps. I also have bitmaps for focused and disabled.

The user can always choose to override the paint event and do it from scratch.

Is this a good idea or a terrible one to use themes and theming? Should I stay generic like GuiChan?

As game developers , which would you prefer, (no themes, partial themes, partial themes + bitmaps)?

Thanks

# Answer
> 3 votes
I'd definitely let developers do themes and override things if it doesn't add excessive burden to the average developer, nor decrease your chances of releasing.

Assume that most of your user base will just use the stock methods at first, but the rest will love the fact they can do it different. Or once they've got it working with the stock methods, they'll customize later.

# Answer
> 1 votes
It doesn't seem to make much difference to me - the developer is going to need to be able to customise what gets drawn either way, so whether those customisations are grouped into a theme or not makes little difference. If you're talking about supplying your own themes then that's great but any developer who wants to release the game with the GUI visible is likely to replace your theme anyway.

---
Tags: game-design, c++, gui
---


# Question
Title: Calculating the output of two armies fighting
I am programming a strategic game using Flash. The game works very similar to the famous game "Travian".

My problem is as follows: I am trying to make the calculation of the troops lost as a result of a fight between two armies. The two armies have different types of units. Some of them are stronger against some other units and weaker against other types.

How can I put that effect of this differences in the equation of the fight?

It seems to be easy if they only have att and def points only, but when it comse to the units type dependency, I am lost.

# Answer
In addition to supporting Amit's suggestion of looking at the Lanchester equations, I just want to add that this is a game design decision, not an empirical fact that we can give you. If you want to take unit type into account, you have to decide what that means. This means choosing an equation that includes all the factors that you want your gameplay to include. If you want infantry to be better than cavalry, then you have to decide what that should mean - eg. how many cavalry do you need to equal 100 infantry? And does it matter who attacks who? You seem to be implying that simply giving infantry and cavalry different attack and defence values isn't good enough - why is that? What else are you trying to represent that can't be captured just by those values?

You have to decide which factors you want to model in your game, as they affect the way the players will approach it. These might include unit size/quantity, unit type, unit experience (eg. veteran status), terrain and environmental effects, differences between attacking and defending if any, whether to model damage and attrition or not, whether to model the passage of time during the combat, the ability to withdraw or flee (possibly including modelling of morale), how much randomness you want in the equation, and so on.

Once you know all this, there are several basic mathematical approaches you can take. You could do a round by round "chance to hit" system like many RPGs have, eg. the d20 combat system. You could do a one-round "attack vs defence" weighted coin toss system like the original Civilisation game does. You could have each side generate a score by adding attributes to a random number and whoever gets the highest value wins. And you can permute these systems to work on a round-by-round basis, or to deduct hit points or morale points, or whatever. Any system can work, but you have to balance it the way you want it to play. As ultimately the choice of how to model the combat is a key part of the game design, and is not something other people can just give to you.
> 10 votes

# Answer
For Solar Realms Elite I was inspired by Lanchester's Equations for modeling warfare. I had several simultaneous fights in each round of battle.

In the first fight, everyone attacked soldiers. In SRE soldiers are best against soldiers (it's not rock paper scissors, but infantry, air attack, and deep space). I set up an attack and defense power where soldiers had the best attack:

```
attack_strength = 3*soldiers + 1*fighters + 2*cruisers
defense_strength = 10*soldiers

```

In the second fight, everyone attacked the defense stations. In SRE fighters (air) are best against defense stations (e.g. anti-aircraft):

```
attack_strength = 1*soldiers + 4*fighters + 2*cruisers
defense_strength = 25*defense_stations

```

In the third fight, everyone attacked the heavy cruisers. In SRE heavy cruisers are in space and are best against other heavy cruisers:

```
attack_strength = 1*soldiers + 1*fighters + 10*cruisers
defense_strength = 15*cruisers

```

(I don't remember what constants I used; those are just examples.) In each round of battle the attackers would lose some fraction of the defense strength and the defenders would lose some fraction of the attack strength. I believe this corresponds to Lanchester's Square Law (equations here). I had added randomness but I don't remember exactly where. After each round of battle the armies would be smaller. I put a maximum limit on the number of rounds; after that, the losing side would retreat.

It wasn't realistic to have the infantry on the ground firing way into deep space, but it worked better for gameplay reasons to have all units be able to fight all other units (at reduced effectiveness).
> 15 votes

# Answer
I tend to say ' if you can't find an explicit solution, seek an implicit one'. You could simulate the battle internally until one army is wiped out or retreats(depending on your game's possible outcomes).

I'd use something like this:

For each iteration of the battle, all units are opportunistic, so they try to do the most damage they can. Each unit selects an enemy unit it is going to attack this round, based on the known advantages/ disadvantages.

Then, all subfights are performed. An example:

Let spearmen be effective against cavalary, cavalaray effective against archers and archers effective against spearman.

In a fight between two armies consisting both of al types of these basic units, all spearman would attack cavalery, all cavalery units would attack archers and all archers would attack spearmen. If for example one side had no archers, the other sides cavalery would select the next best type of target (being the enemy cavalery units)

Each unit-attacks-unit event is resolved seperatly, with the losing unit being damaged or marked as destroyed.

After all the individual fights have been resolved, remove all units which have been critically damged or destroyed.

The next iteration starts using the now reduced armies.
> 12 votes

# Answer
I'm beta-testing a game that is currently a simple version of Solar Realms (Star Empire Elite), and I started by using something similar to Amit's equations (above). In particular, I liked the idea of having three phases to the battle, where you had to win two of the three. But I also wanted to introduce an element of randomness into the battle, and for that I was influenced by some tabletop games.

Processing is a concern if the game is to scale, so I didn't want to follow the method suggested by sum1stolemyname above, although if your game is using the client to process the results, as opposed to a server, this seems to be a good approach.

I decided to break the battle into two phases (analogous to the three in Amit's model): air and ground. I calculate the attack and defend strength, and adjust the attack strength down by a fraction (to give the defender the advantage). At that point, if the attack strength and the defend strength are equal, the attack has a 50% chance of victory. From there, I adjust the percentage chance of victory up or down based on how much more (or less) strength the attacker has compared to the defender. Here are some simplified equations for air:

```
air_attack_strength = 1 * soldiers + 10 * fighters
air_defence_strength = 2 * soldiers + 25 * stations

differential = (air_attack_strength - air_defence_strength) * constant

chance_of_victory = 50 - differential

```

I specify that the chance\_of\_victory can never be larger than 80 or less than 5. From there, I just generate a random number out of 100, and then carry forward that result to the land battle.

One thing I have not solved to my satisfaction is the casualty rates. But I'm thinking that a good way to figure this out would be to compare the chance\_of\_victory to the random number generated, and use that to take a fraction of the attacking-defending forces as casualties.
> 3 votes

---
Tags: game-design, architecture, mathematics
---


title: Farseer and 2D Action sidescroller game

text:
# Question
Title: Farseer and 2D Action sidescroller game
I'm thinking about using Farseer inside my game (I'm not good in physics), which isn't a bad idea. However something happened while I was thinking about that, I found this tutorial:

http://www.sgtconker.com/2010/09/article-xna-farseer-platform-physics-tutorial/

which talks about how to use Farseer, expecially the first part shows how to create a good collision method with a **static object** (like ground!!!), which, partially answer to my old question:

2D Side Scrolling game and "walk over ground" collision detection

So, is a good idea to use a physics engine to create a "walkable" terrain in a game? (obviusly I will use it for jumps and other things too) Is it a bit exaggerated, I mean, does it creates performance issues if I use it for something like ground collision which happens **all time** (except when jumping) in a game?

If it's ok I've solved 2 questions with 1!

Thanks for suggestions.

# Answer
**No it will not create performance issues as long as the quantity of checks per frame are not too much for the engine to handle.**

For a physics engine on a modern computer I don't think there would be any problems with anything less than 1000 collision tests a frame, depending on your physics engine you can have many more tests per frame.
> 2 votes

---
Tags: xna, 2d, physics, collision-detection, side-scroller
---


title: Phone for Android game development

text:
# Question
Title: Phone for Android game development
I've been developing casual iPhone/iPod Touch games touch for about two years. I'd like to port some games to the Android platform. Since I'm stuck w/ a two year iPhone contract I don't want to get an Android phone that requires a service plan. **What is the best phone to get for development in this situation?**

# Answer
**Updated September 2011.**

To develop on Android, you need many devices for two reasons:

* Screen Size (from 1280x800 to 320x240)
* Hardware platform: GPUs and CPUs

But if you need one, buy a Nexus S (S or One), because it is an official Google Phone. You will have GingerBread (Android 2.3). And you must know that Debug on NDK with Android is bugged. You can't debug easily multi-thread programs (OpenGL). There is a fix in NDK r6 ( or r5) but its needs a Gingerbread phone. For HoneyComb dev (Tablet), you need a Tegra2 device (or OMAP 44x0).

To check your Android games, i recommend to have one device per GPU family at minimum.

So in September 2011, I recommend to have these phones:

* Galaxy S or Nexus S (for PowerVR 540 and Android 2.3.3)
* Galaxy S2 (for Mali 400)
* HTC Sensation or HTC EVO 3D (Andreno 220 + 960x540) or Sony Ericsson Xperia Play (Andreno 205 + GamePad)

and these tablets:

* Motorola Xoom, Acer Iconia, Asus transformer, Galaxy 8.9 or 10.1 (Tegra2 + Honeycomb)
* Archos G9 or Galaxy 7.7 (OMAP 44x0)

But, i check on these devices too:

* HTC Desire HD, Z or S (Andreno 205)
* Nexus One (Andreno 200); I aim framerate \> 25fps on this device

Outdated devices:

* Droid (PowerVR 530): GPU is too slow
* A101IT archos (tablet resolution 1024\*600) performance is very low
* Spica, Moment, Naos & Taos: OpenGL are so bugged... to be compatible with these devices you should verify each OpenGL command;
* HTC G1, HTC Magic or HTC Hero: if you plan to develop OpenGL ES 1.x, verify on these devices
* Wildfire (small resolutions)

I'm one of developper of Moblox (a featured Android game) and i needed all these phones. If you don't use OpenGL, you can have only one Phone and check with Emulator. For HoneyComb, the emultator is so slow that i recommend a real device.

Ps: i made a collections of OGL 2.0 extensions on this page

ps2: my gpubench can give hints about GPU on Android (results)

**Changelog**

* September 2011: add tablets, move Droid and A101G8 in outdated devices
* May 2011: move Spica in outdated devices
> 14 votes

# Answer
I think you can buy most motorola phones without a contract. If you did want to use them they would only work on Verizon. Like you can probably buy the Droid 2 by itself.
> 5 votes

# Answer
The Moto Droid seems to be a decent benchmark to go by, as most android phones coming out now either match or exceed its specs, and the Droid is one of the more popular android phones out there currently. You can find unlocked Droids on ebay for ~$100. One of the nice things about android is you can develop and test on any android phone, so if you know anyone with an android phone (when you want to test on different handsets), you can just connect, deploy, and test.
> 2 votes

# Answer
what about HTC Desire? I search a lot about android phone, Moto XT720 has a good price, but it's ROM is too old, even haven't Android 2.2. Buy a Android phone is very confused me...
> 1 votes

# Answer
I suggest you get at least two phones. An older model like HTC G1, HTC Magic or Samsung Spica (or generally something with the lowest specs you want to support), and a newer model like Nexus or HTC Desire. Ideally you would like to test your game on as many phones as you can get (See Ellis answer) but not everyone could afford that many phones. This setup gives you basic coverage which can be improved by testing on friends phones for example. If you're game isn't too complex and you got a good development computer you can get even away with using the emulator in early stages of development.
> 1 votes

# Answer
Actually I came across a device that was custom built for just developing android games on it. Been a while since I have worked with android.. Here is the link.
> 0 votes

---
Tags: android, hardware, porting
---


# Question
Title: Drawing polygons with a repeating texture on iOS
I want to draw a terrain for a 2d game, and this terrain is defined by some rotated rectangles and circles, I want to draw my terrain as if it was a repeating texture clipped by those forms. I already modified the cocos2d draw primitives methods to draw them using a triangle fan, but I'm not sure how to apply a texture on them.

# Answer
Very difficult to make out what it is you are asking from this question.

1) The one thing you might allude to would be the UV wrap mode on a mesh. You bind the texture, render the mesh (of course, depending on ES2.0 shaders or fixed function ES1.1), and make sure the wrap mode is set to repeat, not clamp.

Also, for more thorough information, read this page : http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-part-6\_25.html
> 2 votes

---
Tags: opengl-es, cocos2d-iphone
---


title: Marketing: Angry Birds - How it's done

text:
# Question
Title: Marketing: Angry Birds - How it's done
Why do some apps, like Angry Birds, dominate the market while other cool/fun/addicting apps are never heard of?

I'm trying to figure out the best marketing strategy, or best way to sell an app to mass market.

Does anybody have any ideas or things they noticed about the marketing of major blockbuster apps, like Angry Birds, why they get so popular and stay at the top of charts.

Thanks for any ideas, comments ...

# Answer
> 22 votes
Angry Birds matches the iPhone market very well.

* Short gameplay sessions match the phones usage patterns
* High art production values
* Setting/Characters that are appealing to both sexes
* Very simple mechanics that offer mastery potential in time

This make it a game well suited to the platform and it can appeal to the full range of iPhone users. This is important as a lot of sales on the phone from from word-of-mouth recommendations.

Additionally they have followed a very smart plan of regular updates and additions which get people talking about the game again and keeping it in the top of the charts. On iPhone it is absolutely crucial to get your game in the top 25. This is because of the way visibility works within iTunes and on the phone. Particularly with casual users you don't want them to have to search for your game.

# Answer
> 8 votes
With Angry Bird Seasons, they have a really good ploy to keep you playing the game. They are only releasing one level every day. This keeps users coming back every day to play the next level. For the Android market, this is a fantastic idea because that means people are going to be coming back every day to see your ads.

# Answer
> 7 votes
The developer of TrainYard, a game that was second highest on the app store recently posted in depth information on pricing, marketing and strategy that he noticed while competing with angry birds.

Read more here : http://struct.ca/

# Answer
> 5 votes
Well I agree with `wkerslake`. I think other strategies which matter are visibility of your app. You need to set up a social networking account that can keep tabs on bugs being reported and updated real time. Helps a lot in-situations where people who use the app feel their concerns are being addressed.

From personal experience, we once created a word game app and the dictionary used in our application did not have a couple of words. This made users quite annoyed and we were not aware of the missing words. People sent out screenshots of the issue, and we were glad to resolve the issue in no time. We also incentivise users with previews to new launches, beta launch enrolment and free premium subscriptions. Community around your game will be more than sufficient marketing.

# Answer
> 0 votes
Having read this *rumour* I think that investor with money and media/business contacts may help somewhat.

---
Tags: iphone, marketing
---


title: Has anyone used MonoTouch for a game?

text:
# Question
Title: Has anyone used MonoTouch for a game?
With the pending release of MonoDroid we have decided to revisit MonoTouch as a possible alternative to gearing up some Objective-C skills. I was wondering if anyone had any experience and would share the gotchas before everyone else hits them. Set to CW, one hurdle per answer please.

MonoTouch allows C# development of iPhone and iPad applications with access to native code libraries.

# Answer
There are a handful of games built with MonoTouch, we just started tracking apps built with it recently, you can see them here:

http://monotouch.net/Apps
> 7 votes

# Answer
I haven't used it, but my biggest reason for not using it is that there's a possibility that Apple could at any time remove all apps made with MonoTouch as it seems to go against the developer agreement:

> Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs. Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).

Having said that though, Unity licenses MonoTouch and they seem to have a decent relationship with Apple.
> 5 votes

---
Tags: iphone, c#, cross-platform, mono
---


title: How to use the testbed with box2dflash?

text:
# Question
Title: How to use the testbed with box2dflash?
I have made games with box2dflash, but how much ever i have wanted to try out the test bed, the resources on the net don't help me. I have a folder called Testbed and various Test???.as files inside it. It would be a great help if somebody could just jot down how the testing of a box2dflash game is done. Thank you

# Answer
```
        package TestBed{

            //Do your imports

            public class TestEmptyTest extends Test{

                public function TestEmptyTest(){
                    //Initialise your objects here
                }

                override public function Update():void {

                    //This is called for you by the Test class
                    //But you call this manually, to keep it syncing
                    super.Update();
                }

            } //TestEmptyTest

        } //TestBed

```

So, this is JUST the basic test class. If you throw this into the source path of your project, you should have a fully functional testbed test ready to use. If you want to see WHERE the test is added to the testbed itself, see the Main.as file in the root of the examples folder. This powers the TestBed application. More Notably, Look for the following on line 97 :

```
        var tests:Array = [

```

You can add your test by class name (TestEmptyTest), and it will show up in their list.

What makes it work?

1) Make sure you have the class path able to see the testbed folder

2) import TestBed.\*; will bring the class into the Main.as already

3) creating a new instance of your class. Their framework does this for you, as long as you add it to their array.

Hope that helps!

> More importantly, you gave almost no information. Some things you might want to include :
>
> Version of Flex/Flash (And IDE)
>
> Version of box2dflash
>
> Code snippet of what it is that isn't working.
> 2 votes

---
Tags: box2d, testing
---


title: game design improvement

text:
# Question
Title: game design improvement
I was having a discussion with my developer mate on following game design.

I have a collection of `Move` in the `Game` class. my developer mate is asking me to remove the collection and only have the current move information there.

what is your suggestions?

```
public class Game
{
    public String Id { get; set; }
    public String CreatorId { get; set; }

    public List<Player> Players { get; set; }
    public List<Move> Moves { get; set; }
}

public class Player
{
    public String Id { get; set; }
    public String Name { get; set; }
}

public class Move
{
    public String Id { get; set; }
    public String PlayerId { get; set; }
    public String PlayerName { get; set; }
    public String NextMoveId { get; set; }
    public String NextPlayerId { get; set; }
    public String Position { get; set; }
}

```

# Answer
I would say this question isn't related to game design but to software design or software architecture. Anyway, back to topic:

You question is really short and I can't tell what the classes are for but I will do a educated guess. I think `Game` is your global game context, which contains information several other objects are sharing.

The main question you should answer is: Does any other object need a list of `Move` or just the current one.

Sorry for the general answer but I can do bettw with more information.
> 2 votes

---
Tags: game-design, c#
---


# Question
Title: How do you design a record/replay system for a frequently changing game?
I'm working in a free MMORPG and I have a problem.

I'm (with other people) developing a video recording system for the game. The idea is basically: we record all the packages sent & received with timestamps, plus some local data from the client, and then dump it in a file. For playing the video, we just emulate everything that's on the file. We also have an option to export the video to avi with ffmpeg.

The problem is: when we change between versions of the game, it is hard to maintain backwards compatibility for the video (commands added / removed, function changes, etc). Is there a good way to handle this problem? instead of having a bunch of different players and choose the right one for each version of the video file?

It would be helpful to know how does other games handle this situation.

Thanks for the help, sorry for my english.

# Answer
> 8 votes
Our basic rule is to never change an existing packet type. Everything is either added at the end of an existing one, or a new command. This also makes it far less likely for two people to stomp on each other's work.

# Answer
> 5 votes
It's not inconceiveable, especially on a PC, that they just version the gameplay code and bump the version when they make a change that affects the replay system. If replay file is tagged with the version of the gameplay code it was created with and the client still has access to that version that it should work fine.

# Answer
> 1 votes
One way of tackling this is along the lines of a game called "Heroes of Newerth." (which changes every +/- 2 weeks) From what I can tell they:

1. Use diff patching for the game and replays.
2. All replays are stored on the cloud. They eventually expire.
3. If the user wants to watch an old downloaded replay they need to use the "Compatize" button first.
4. It looks like this either remote diffs to the latest version; or in the event that the replay is no longer stored, uploads it and then does the remote diff.

Because I don't work at S2 I clearly can't say that is definitely how it works. However, I have noticed a marked download size trend associated with the age of the replay.

Either that, or they add entity patches to the replay (e.g. spell X has Y effect instead of Z effect). If packet-related information is also stored in the entity configuration this entity hot-patching would allow you to understand older packets as well.

I definitely wouldn't store historical behaviour on the client because that can get enormous very quickly. Especially when the client is updating from e.g. 10.1.0 to 10.2.0 (as they need to download every patch between the two versions, instead of the final patch).

Google Protobuf is a good idea as a serialization layer because it supports stuff like this by design.

---
Tags: mmo, multiplayer, video, game-recording, patching
---


# Question
Title: Resources to learn programming rigid body simulation
Where I can start learning about simulating rigid bodys 2d and 3d ?

# Answer
This seems like a logical answer :)

1) Read theory on the subject. Understand the higher level concepts first. Check the www.gamedev.net article sections they have plenty, as well as google books. Also, this link has some nice references : http://chrishecker.com/Physics\_References

2) Read existing libraries. 2D - Box2D for 2D physics is a really good reference of rigid body simulation in 2d. http://box2d.org/ 2D/3D - http://bulletphysics.org/wordpress/

3) Implement. This taught me so much about understanding other engines. Start with the simplest of maths, implement it. Even the simplest implementation will boost your understanding of the systems involved.
> 4 votes

# Answer
Another great resource on the topic are David Baraff's papers. Here is one of them including source code:

"An Introduction to Physically Based Modeling"

http://www.cs.cmu.edu/~baraff/sigcourse/notesd1.pdf
> 1 votes

# Answer
A source that really helped me was using managed language code libraries. You then have the ability, through reflector, to see the code behind the methods that an engine uses. Much of this 'code behind' isn't available for view online.

The book that had the best influence on my understanding of the subject was this one:

http://www.amazon.com/Game-Physics-Interactive-3d-Technology/dp/1558607404/ref=sr\_1\_5?s=books&ie=UTF8&qid=1291983195&sr=1-5

If you are going to buy books, consider this well respected one too(it's related to physics):

http://www.amazon.com/Real-Time-Collision-Detection-Interactive-Technology/dp/1558607323/ref=pd\_sim\_b\_1
> 1 votes

---
Tags: physics
---


# Question
Title: OpenGL and 3ds model loading: Path of least resistance?
Hey guys, im working on a final class project for a graphics class, and me and a teammate are making a simple 3d tower defense game.

We're currently planning on using 3ds models and drawing them with OpenGL.However, niether of us have a lot of practice/experience with loading/drawing models.

What is the **fastest and/or easiest** (not neccesarily the best or most feature-implemented) way to load a 3ds model and draw it with a OpenGL/glut setup?

# Answer
> 1 votes
It is easy to load 3ds files using: http://code.google.com/p/lib3ds/

It also comes with a OpenGL sample.

But I think it is better to use another format, 3ds materials name limitation are a real pain.

# Answer
> 3 votes
The easiest way will be load obj files, like so(files you are interested in -\> `glm.h/cpp`):

http://www.xmission.com/~nate/smooth.html

It comes with examples.

I personally feel, that if you are learning, you should make one yourself. Not as feature filled as above, but a simple obj loader that reads vertices/normals/texture co-ords and perhaps the material as well.

It will take you a few hours at most to figure this out (speaking from experience - when I didn't have experience :). This will make you understand the guts of all loaders and their possible limitations. You can then switch to more feature filled loaders while at the same time knowing what is going on behind the scenes so that it does not seem like `magic` anymore.

# Answer
> 3 votes
I have good experience with AssImp. Have a look: http://assimp.sourceforge.net/ It's well documented.

---
Tags: opengl, models, loading
---


# Question
Title: How do I create user-friendly, unique game IDs?
How do I create unique game IDs which are also user friendly -- so that one user can easily give that game ID to someone else for joining the game.

I am creating my game in Silverlight with C#.

# Answer
> 6 votes
If you have an authoritative source, that problem is easy (which I'm assuming if the user is putting in an ID to connect to a game then that is getting redirected using some central server). Just use an algorithm like http://www.safepasswd.com/ does to make UIDs which are basically dictionary words + small numbers. If the number of servers is relatively small you could even do a naive algorithm that just picks something random until it isn't currently in use.

If you want your clients to be the source of the UIDs, you're going to have to throw away the user friendly portion of those IDs. But it's easier to do on the coding side since you'd just be using System.Guid.NewGuid().ToString(). That is for all intents and purposes guaranteed to be unique 100% of the time. source

Then again, GUIDs are a little overkill. It would be easier to remember IPs or usernames b

# Answer
> 3 votes
One approach would be to use a dictionary, and select words based on a numbering scheme. Perhaps use a unique 32-bit integer to identify each user and for each of the 16-bit words, index a dictionary (array of words). This way, you can represent their id using actual words and each identifier would be unique.

Another approach would be to implement something similar to what Steam uses: allow users to login with an id they chose themselves, and later let them specify any display id they want. For instance, their login id could be their email and their display name could be their first name. In this way the user can share their unique identifier but also be identified by a name of their choosing.

# Answer
> 3 votes
FuzzYspo0N's answer in the comments is a very good one. Basically this problem boils down to making game IDs unique enough to avoid collisions, without making them arbitrarily complex. Standard 128-bit GUIDs get their uniqueness by using local information (like your MAC and other factors) to make the likelihood of a collision between machines very small, then add a random and time based factor to make the likelihood of a collision within that machine very small.

You can follow the same strategy to generate your own IDs. Start with something memorable to the user but relatively unique (if the user has a global username that's a good start, or the machine name/IP), and add other factors until you've generated something unique. By picking something local like machine name, you restrict the set of potential collisions enough that you can start to query if there are any. For example, once you've restricted it to just that user, or just that machine, you know exactly where you need to go to check whether or not that UID is already in use.

For example if I know my username is unique system wide, then MrCranky:1 is a valid UID. If I can check whether MrCranky:1 is already in use (by some other method), then I can just keep trying numbers until I find a unique one.

By using some other factor (like randomness or time), I can increase the likelihood that I pick an unused ID first time. E.g. If you know you can't feasibly create more than one session a second, then using MrCranky:122730 (the current time, to the second) will get me a unique ID that's relatively memorable to the user.

As long as you have some piece of relatively unique information (doesn't have to be perfect, just mostly unique), you can use that as a starting block, and that means the truly unique portion (an integer code of some kind) can be much much shorter, and thus the UID is more memorable.

# Answer
> 0 votes
You could use a player's email address as a unique identifier. I'm sure they can remember that :)

---
Tags: c#, silverlight
---


# Question
Title: How to sell Android game if selling through Market is not available in your country
Android Market doesn’t allow developers from my country to sell app. From what I understand the only chance to make some profit is to place ads in my application.

Does ads make a decent profit or is there some other way to earn money are there any other payments system available for Android to bypass Google’s limitations?

# Answer
> 4 votes
You can use PayPal in some of the following ways:

* Generate a unique download url for your app that works for a limited time.
* Generate an unlock key that unlocks your free version.

According to this article PayPal can already facilitate in-app purchases in some countries. When this will become available outside of the mentioned I don't know.

# Answer
> 1 votes
You can use YAAM, an alternative market, with Paypal paiement. Like the market, there is an application which manages update. For Moblox(our game) customers, it is very easy.

YAAM is an open source product, so you can developp your own Market if you want.

# Answer
> 0 votes
An example that came to mind for the situation you described is how Rovio initially launched Angry Birds on android. Angry Birds for android started by being available only on http://www.getjar.com/ with ad support in game. Eventually they moved into the android market, as well, but the game was free either way in this case, so revenue would be coming through ads on the android side of things.

---
Tags: android
---


# Question
Title: Can't figure get the conversion from cartesian to spherical("polar") correctly for my orbiting camera
The two angles from the polar coordinate system are defined as hRotation and vRotation

This is how they are converted from polar to cartesian:

```
    // Get the distance between the object and the camera
    float distance = cam.getLocation().distance(RotationTarget);

    Vector3f pos = new Vector3f(distance * FastMath.sin(vRotation) * FastMath.cos(hRotation),
                                distance * FastMath.cos(vRotation),
                                distance * FastMath.sin(vRotation) * FastMath.sin(hRotation));

    // Add in the objects position to make the new relative position of the camera
    pos = pos.add(RotationTarget);
    cam.setLocation(pos);

```

Now the problem is when I try to get hRotation and vRotation from cartesian coordinates for the to initialize hRotation and vRotation, rather than setting them to an arbitrary value and having the camera jump each time. The camera is generally free roaming "a fly cam" but when an object is selected, the user can hold shift to rotate the camera around the object. So I need to base hRotation and vRotation off of the coordinates of camera and object, here is my code so far, but the issue is that the Camera will mirror its rotation rather than allowing me to fully rotate. For instance I can rotate to the left but it snaps to opposite angle from the right. I know I probably need to invert the angle when something is less than something, but I can't figure out what it is...

```
    float distance = cam.getLocation().distance(RotationTarget);

    Vector3f diff = cam.getLocation().subtract(RotationTarget);

    vRotation = FastMath.acos(diff.y / distance);
    hRotation = FastMath.asin(diff.z / FastMath.sqrt((diff.x * diff.x) + (diff.z * diff.z)));

```

Thanks, -Tim

# Answer
By using acos you are limiting vRotation to the range \[0,pi\], and by using asin you are limiting hRotation to the range \[-pi/2, pi/2\]. In other words, you are only able to get half the period of the trig functions in each case. To fix this you need to check some cases (CAST rule).
> 2 votes

# Answer
Thanks for the help! I finally got it to work the way I wanted. Here is the code:

```
    float distance = cam.getLocation().distance(RotationTarget);
    Vector3f diff = cam.getLocation().subtract(RotationTarget);

    vRotation = FastMath.acos(diff.y / distance);
    hRotation = FastMath.acos(diff.x / FastMath.sqrt((diff.x * diff.x) + (diff.z * diff.z)));
    if (diff.z < 0)
        hRotation = -hRotation;

```
> 0 votes

---
Tags: game-mechanics, camera, rotation
---