• 11
• 14
• 19
• 27
• 9
• ### Similar Content

• Hi everyone! I'm currently working on a series of books about 2D Shader Development.

The idea is to synthesize a bunch of techniques that are specifically useful for 2D, even if they work on 3D as well.

I released the first book last week. It's 4.99 on Amazon or free on the series website, https://www.2dshaders.com

This is an independent initiative, I don't work for any publisher whatsoever. The contents of the books are the result of a 4-year span where I started teaching this in Argentina and USA, always making the workshop better. Now I'm expanding it to make more sense in book form.

I'd love to hear your opinions on the idea and if you get the book let me know what you think.

By the way, the examples are in Unity, but the concepts from the book should be easily transferable to any graphics api/engine.

Hope you like it!

• While looking out for that pesky Terrator, our little alien is doing a bit of relaxed mining down on the new gas planet "Lelantos" this weekend....

• I have a native iOS game (objective c, XCode build) which I am considering to port to other platforms.
Core gameplay is based on solely on geographical maps, and custom drawing over maps. It also has Core Data. This part is complete in development.
What is not done yet is: monetization, gamification (leaderboards, challenges) and multiplayer functionality.
As I think more about it, I am tempted to think if this is the right time to move to a cross platform tool such as Unity. But before dedicating time to port my 5 years side-project effort in Objective C, I really want to know if its worth it.
- Does Unity support such plugins / assets that will fulfill all my above requirements?
- Unity Personal seems to have only 20 concurrent users - is it too costly scaling if I decide for extending to web and android platforms?
- What is the general workflow involved in publishing to iOS, Android, PC, and web platforms while using Unity? I mean to ask about various points of signing stuff, paying fees and getting certified.
- How long will it really take to port my entire Objective C project into Unity? I am somewhat familiar with C# but I am finding it hard fidgeting with Unity IDE as lot of things are focused around FPS and 3D while my game is still 2d - not much action involved. I seem bit overwhelmed by the list of features I see there. All in all, I do not want to lose my momentum while still making sure its portable to everywhere.
- Any assets I could use (for free to try basis in debug) that are relevant for my game?
- Last but not the least, are there any costs that I need to be paying upfront to Unity, for using it (apart from their monthly subscription model)? I don't understand their costing for multiplayer in conjunction with their subscription fees - if someone could kindly elaborate.
• By GytisDev
Hello,
me and few friends are developing simple city building game with unity for a school project, think something like Banished but much simpler. I was tasked to create the path-finding for the game so I mostly followed this tutorial series up to episode 5. Then we created simple working system for cutting trees. The problem is that the path-finding is working like 90% of the time, then it get stuck randomly then there's clearly a way to the objective (tree). I tried looking for some pattern when it happens but can't find anything. So basically I need any tips for how I should approach this problem.
Use this image to visualize the problem.
• By aymen
please any know how can i' calculate the centroid from any number vertices

# Unity Planet and inhabitants

This topic is 2810 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all!

I've joined this amazing community to ask a question. I'm not sure wether is it posted in the correct section or not, so sorry if it's wrong.

I have programmed my own personal OpenGL 3D engine in C++ and now I have some population (little balls, for example) walking freely in a 3D plane surface. What I need is to adapt this system into a "real" planet, which it means that the inhabitants (whatever they be) must move in the spherical environment.

I've no idea of what I should do to achieve this. Supposing that I know the radius of the planet, which doesn't rotate, and it also has an attached collision model, what could be the best way to mantain the inhabitants on the surface (like in Mario Galaxy)?

Any idea would be very apreciate! Thank you and excuse my english (I'm spanish).

##### Share on other sites
I suppose you're aiming for a newtonian model. With your average shooter, you have the same gravity vector for every object, probably (0, -9.81, 0), depending on which axis is your top-down axis. If you want your objects to "fall" towards the center of the sphere, then you need to calculate the gravity vector yourself, which depends on the position of both objects involved:

*edit*
I thought I'd explain those variables:
-G is the gravitational constant that you can tweak until you get visually pleasing results
-m1, m2 are the masses of both objects involved
-r² is the squared distance of the center of masses of both objects
-You can ignore e in your case

You can of course find a pleasing value for G * m1 * m2 alltogether, if you like.

Since you want your spheres to "move" along the surface as well, you simply need to move them along one (ie. any) vector that is right angled to the gravity vector you calculated above.
If you keep your increments/timesteps small enough, it will appear as if those spheres are moving along the surface.

##### Share on other sites

However, it seems too much complex to me and I'm probably leaving it. Can't figure out how to find this vectors and my entities in the project don't have masses. Introducing gravity will probably get me crazy.

Thank you anyway!

EDIT: Thanks for the "edit"... I'm looking at it now!

The difficult part for me is to decide which are the initial positions for the inhabitants on the planet... just to calculate the r value. Then I'd need to specify the limits for the balloons not to cross the surface, etc. Finally, I would have to operate with the Force(r) result within the whole process.

##### Share on other sites
Perhaps the first thing to decide is whether you want to use spherical coordinates for each "inhabitant," or Cartesian coordinates.

Spherical coords may be easier in some respects to position each inhabitant. Neither coord system will be a lot of fun as you'll probably have to convert back and forth for the purposes of moving them and drawing them.

E.g., each inhabitant could have 2 angles (equivalent to latitude and longitude) and a distance from the center of the sphere. The distance isn't necessary if they'll always be on the surface (not burrowing or jumping).

Movement would then be just a small change in one or both the angles. To draw them, however, you'll have to convert those angles (using the radius) to Cartesian coords. Collisions could be detected by comparing either angles or Cartesian coordinates for some small delta between them.

##### Share on other sites
You may use a spherical coordinate system to specify the position of your inhabitants on a sphere. A spherical coordinate consists of 2 angles and a radius: (r, a, b). You can think of 'a' being the latitude and 'b' being the longitude.
Assuming you use radians to use describe angels: -pi/2 <= a <= pi/2 and -pi <= b <= pi. You can easily use a random number generator (boost::random) to come up with values for both angles. The radius you want to use here consists of the radius of the planet itself and the bounding radius of your inhabitants: r = r_planet + r_bounding_inhabitant
Spherical coordinates alone are no use for you, since OpenGL uses a cartesian coordinate system. However it's quite easy to obtain the latter:
x = r * sin(a) * cos(b)y = r * cos(a)z = r * sin(a) * sin(b)

(Assuming y is your up-axis, but that should be the case)

About the masses, there's no need for them. You may use G * m1 * m2 = 1, just as an example, though I'm pretty sure you will need to experiment with this factor until the balls "fall" with an acceptable acceleration.

However since you're not looking for such a "detailed" model you may do something else. Simply make your inhabitants change their spherical coordinates over time by a constant factor. An inhabitant may increase both angles by a certain delta (a_delta, b_delta) each timestep. All you need to do is to calculate the cartesian coordinates each timestep as well, in order to render the inhabitants:
class inhabitant{    spherical_coordinate coord;    spherical_coordinate speed;    vector3              pos;    inhabitant()    {        boost::mt19937 rng;        boost::uniform_float<> latitude(-pi/2,pi/2);        boost::uniform_float<> longitude(-pi,pi);        boost::variate_generator<boost::mt19937&, boost::uniform_float<> > lat(rng, latitude);        boost::variate_generator<boost::mt19937&, boost::uniform_float<> > lon(rng, longitude);        coord.a = lat();        coord.b = lon();        coord.r = 10;        // I am kind of lazy right now, but must now do the same thing for        // the speed, although the distribution should be much smaller, otherwise        // your inhabitants move ultra fast        speed.a = speed_lat();        speed.b = speed_lon();    }    void update(float dt)    {        coord.a += speed.a * dt;        coord.b += speed.b * dt;        pos.x = coord.r * std::sin(coord.a) * std::cos(coord.b);        pos.y = coord.r * std::cos(coord.a);        pos.z = coord.r * std::sin(coord.a) * std::sin(coord.b);    }}

*edit* Who dared to ninja me :P

##### Share on other sites
I tried the random initial positions part... and it works!!!

Now I go with the recalc and move. Thank you very much to everybody!

##### Share on other sites
Personally, I'd avoid the use of spherical coordinates for this; I'd recommend sticking with Cartesian.

Here is a recent thread on the same topic that may give you some ideas. (Be sure to check out the Gamasutra article.)

##### Share on other sites
The problem now is that I want to move the inhabitants on the surface of the planet but not in terms of spherical coordinates. To put it simply, I need to move and rotate these entities in a "local way" (like you would do in a plane) without thinking in angles, latitudes or longitudes.

The matter with the spherical coordinates is that I can't make my inhabitants trace curves (I can only move them in the four directions plus in diagonal) and it's impossible to keep them facing their front.

Maybe I'm not explaining well enough. This is a representation of what I want:

HERE

##### Share on other sites
Quote:
 Original post by abadosaThe matter with the spherical coordinates is that I can't make my inhabitants trace curves (I can only move them in the four directions plus in diagonal) and it's impossible to keep them facing their front.

It's not impossible. In order to make them move in curve you simply need to change the velocity vector over time. The example I gave you above used a constant velocity but can simply use any formula you want to make the velocity change.
Just as an example, the following should make your inhabitants go in circles (unless I'm not thinking straight again, it's hot here):
void update(float dt){    spherical_coord speed;    speed.a = sin(dt);    speed.b = cos(dt);    pos += speed;}

It's neither impossible to make them facing their front. Given their current position and their next position (ie. 'pos' and 'pos+ speed') you simply need to transform both into the cartesian coordinate system:
vector3 curr_pos = transform(pos);vector3 next_pos = transform(pos + speed);

Then you can use those 2 vectors to describe the rotation of your inhabitants:
vector3 planet_center = ...;vector3 facing = next_pos - curr_pos; // This is where they lookvector3 up     = curr_pos - planet_center; // This is their local up-vectorvector3 side   = cross(facing, up); // This is their side-vectormatrix3x3 rotation = matrix3x3(norm(facing), norm(up), norm(side)); // Those 3 vectors already describe their rotation, simply build a matrix from them

##### Share on other sites
Oops, I can't get it to work...

I think the method proposed by jik could be a good choice. Using spherical coords when I need to work with cartesian seems to me too much tricky.

I never used vectors like forward, yaw, etc. but I'm using matrix transformations instead. This may be the reason I can't understand your last indications.