Page 1 of 1

Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 3:24 am
by dudeabot
hello, on "normal" games the gravity usually is (0,-1,0), but how would one work to get a gameplay like Mario Galaxy? Considering it would be possible to use any mesh shape (mostly spheric). I was trying to get a general algorithm idea, but i think my physics are bad :P first, i though about it would be possible to stick with the (0,-1,0), like a localized physics, but how would it be to move the character through the surface?

any input is appreciated!

Re: Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 1:30 pm
by Pyritie
Could you post a video or something? I don't think all of us have played mario galaxy. (I know I haven't :P)

Re: Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 3:41 pm
by Kojack
If you find the closest vertex on the mesh to your current position and use the reverse of it's normal as the gravity. This should let you run over uneven terrain (as you run up the side of a mountain gravity shifts so it's like you are on flat ground), and even orbit it if you move fast enough and jump. :)

Re: Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 4:34 pm
by dudeabot
Pyritie wrote:Could you post a video or something? I don't think all of us have played mario galaxy. (I know I haven't :P)


i havent either :P http://www.youtube.com/watch?v=eqOSSr23i6w

If you find the closest vertex on the mesh to your current position and use the reverse of it's normal as the gravity. This should let you run over uneven terrain (as you run up the side of a mountain gravity shifts so it's like you are on flat ground), and even orbit it if you move fast enough and jump.


thanks, ill try this!

Re: Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 5:46 pm
by dudeabot
hmm how would i go to get the nearet vertex, do a raycasting? if so where to shoot the raycast from (i assume somewhere near the player, but the terrani isnt flat)

Re: Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 7:31 pm
by KungFooMasta
You could try keeping track of the current 'body' the character is associated with, and pull the characters towards the body at all times. Every time the character touches a body, it updates the body associated with the character. I think this would only work well for spherical bodies, you would need other rules for non-spherical ones.

Re: Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 7:42 pm
by KungFooMasta
ok I watched the video. I think you can just assume the character is always upright, and pull him down according to his local NEGATIVE_UNIT_Y direction. If he is not always upright, you can track the last upright position and pull him in the previous local NEGATIVE_UNIT_Y direction.

Re: Mario Galaxy game-like

PostPosted: Thu Mar 12, 2009 9:33 pm
by Kojack
hmm how would i go to get the nearet vertex, do a raycasting? if so where to shoot the raycast from (i assume somewhere near the player, but the terrani isnt flat)

Get access to the terrain's vertex buffer (you can do that from an entity, various places on the wiki and forum talk about it). Loop through each vertex and test it's distance to your position (simple vector magnitude) to find the closest. Now set your gravity to be the negative of that vertex's normal and rotate your model (and camera) to be upright relative to the normal.
Of course for a detailed landscape that could become slow, and every free moving physics body will need to do the same thing to get their own local gravities, so it might be wise to create an octree of the terrain so you can quickly look up a small number of vertices around your current position instead of testing all of them.

Re: Mario Galaxy game-like

PostPosted: Fri Mar 13, 2009 12:21 am
by KungFooMasta
Was my method not feasible/possible, or were you just answering his question? :P

Re: Mario Galaxy game-like

PostPosted: Fri Mar 13, 2009 1:30 am
by dudeabot
Kojack wrote:
hmm how would i go to get the nearet vertex, do a raycasting? if so where to shoot the raycast from (i assume somewhere near the player, but the terrani isnt flat)

Get access to the terrain's vertex buffer (you can do that from an entity, various places on the wiki and forum talk about it). Loop through each vertex and test it's distance to your position (simple vector magnitude) to find the closest. Now set your gravity to be the negative of that vertex's normal and rotate your model (and camera) to be upright relative to the normal.
Of course for a detailed landscape that could become slow, and every free moving physics body will need to do the same thing to get their own local gravities, so it might be wise to create an octree of the terrain so you can quickly look up a small number of vertices around your current position instead of testing all of them.


thanks!
though i was thinking it will find some possible solutions, and it has to be decided accordingto movement direction (have to do some math here :|)

ok I watched the video. I think you can just assume the character is always upright, and pull him down according to his local NEGATIVE_UNIT_Y direction. If he is not always upright, you can track the last upright position and pull him in the previous local NEGATIVE_UNIT_Y direction.


i think the problem with this, is to know which direction

Re: Mario Galaxy game-like

PostPosted: Fri Mar 13, 2009 6:32 pm
by Kojack
Was my method not feasible/possible, or were you just answering his question? :P

I was answering the question I quoted. :)
Not saying your method won't work too, that's just my guess at how it could be done (having never played the game either, although my students did modify their Mawashi Madness game to turn into Mario Galaxy using multiple spherical gravities in Bullet.

Another game with cool gravity effects is Psychonauts.
www.youtube.com/watch?v=IRgMyLCiRpo

Re: Mario Galaxy game-like

PostPosted: Fri Mar 13, 2009 7:52 pm
by _tommo_
I think that Mario Galaxy doesn't use exactly the algorithm described by Kojack as it couldn't work in the actual game... or at least iw would be much more slow and limited.
a small example, using that you could climb any wall, and you couldn't have at all slopes!
Instead in Mario galaxy you are often on slopes, even if the gravity is "curved".

I think instead that they use "Point", "plane" and "mesh" gravity types:

-plane is the gravity we know, used in some portions of the game world;

-point attracts everything to a single point, suited for spheres; often planets like this have some slopes and vertical steps on them, bent on the surface of a sphere; note that this way they are vertical relative to the surface of the planet, and mario slows down to walk on them, or can't at all.
Example: the small bumps and houses on the tutorial planet. Mario's normal IS NOT always the surface normal there.

-mesh is a gravity that uses the algorithm described by kojack on a special Gravity mesh; the mesh is not a simple low poly version of the planet, instead it models the direction of the gravity at each point of the "planet", so that it lacks vertical step or slopes, so that mario can't climb everything like a spider.

At least this is the idea i had after collecting 242 stars :lol:

Re: Mario Galaxy game-like

PostPosted: Mon Mar 16, 2009 12:26 am
by dudeabot
ok

here is what i came so far:

considering the game will have perfect spheres i have the movement like this:

Code: Select all
      
                x= rho * cos(Degree(theta).valueDegrees()) * sin(Degree(phi).valueDegrees());
      y= rho * sin(Degree(theta).valueDegrees()) * sin(Degree(phi).valueDegrees());
      z= rho * cos(Degree(phi).valueDegrees());


rho is the radius of the sphere, Theta (The angle of rotation around the Z axis, where 0 degrees means parallel to the x axis) and Phi (the angle of declination from the Z axis ).

however theres still some issues
the movement doesnt take in account the character orientation, and talking about orientation, how would i align the upvector of the charcater,

for example, i have "currentNormal", and rotate a bit around the sphere, will have a "newnormal" i have to rotate the character to match that normal and align his upvector

im not sure how to do this, i though of getting the perpendicular vector of the normal vector(crossproduct), but there are infinite solutions

i hope it sounded clear :)

Re: Mario Galaxy game-like

PostPosted: Mon Mar 16, 2009 3:23 pm
by _tommo_
so the player moves the angle values, that get translated into the linear ones, right?

(if I understood well :roll: )I think that this is bad for several reasons...
the first is that you should get heavy gimbal lock problems;
the second is that on the "equator" of the sphere your character moves faster than at other latitudes: this because given the same angle, the lenght of its arc of sphere surface increases with the distance from the poles.
So your character moves differently on different regions of your spheres.

For me you should tackle the problem at its origin, and with ogre (and its scene nodes) it should be easy:
in fact the complication is that the "parent node" of the player, in normal games, is directly the Root Node, and because of that you can reason in absolute values.
Instead, here the coordinate system of the player moves according to the surface of the sphere the player stands on.

So, you should create a "system" scenenode wich is the coordinate system of the player, that is placed exactly on the surface where the player is, and which up-vector is the surface normal (it's difficult to explain without an image :roll: ).
Then you have a "player" scene node attached to this one, so that you can translate and rotate the player just like in a normal game (except that to walk you need to move the parent node).

To place the "parent" you need only to rotate via quaternions the radius vector, similar to what you are doing now. Then you set its upvector to the normalized radius.
To orientate or make jump the player you can yaw pitch, roll or traslate the "player" node just as usual.

This way is Ogre that handles your math... so you should avoid many nasty glitches :wink:

PS: Sorry for the never-ending math post :lol:

Re: Mario Galaxy game-like

PostPosted: Tue Mar 17, 2009 12:19 pm
by volca
Why won't you define gravitational shapes of the small "planets" - the gravitational force can be then calculated using a method of the given shape (given the position of an object). The upvector for character is inverse normalized version of gravitational force no matter what happens - just make the physics so the character will have the tendency to rotate feet down. Movement of the character will then be relative to it's upvector.

Or just use the normal, but that could cause some problems with bad tesselation or other than sphere shapes (like cube or torus) - especially when jumping.

This reminds me of Psychonauts - especially Milkman conspiracy level (http://www.youtube.com/watch?v=IRgMyLCiRpo)

Re: Mario Galaxy game-like

PostPosted: Tue Mar 17, 2009 3:12 pm
by Kojack
:)
I posted the same youtube video of psychonauts just 4 posts above yours. :)

The milkman level of psychonauts rocked.

Re: Mario Galaxy game-like

PostPosted: Tue Mar 17, 2009 3:14 pm
by volca
Damn, I should pay more attention!

The whole psychonauts game was a quality refreshment! :)

Re: Mario Galaxy game-like

PostPosted: Fri Mar 20, 2009 12:46 am
by test84

Re: Mario Galaxy game-like

PostPosted: Sat Mar 21, 2009 2:45 pm
by nikki
test84 wrote:I think this is helpful: http://www.gamasutra.com/view/feature/3 ... mario_.php

Hmm... They're just doing a raycast downward from the Player. So you can't really 'jump straight up to a roof'. :)