Hello, how can i make gravity like this http://runevision.com/include/unity.asp?src=http://runevision.com/multimedia/unity/locomotion/planet_walk_01&w=480&h=360&play=true
Draw the objects towards whatever point is generating gravity instead of drawing them down along the -Y axis. That is, have nothing affected by physx gravity (or set it to zero), then all your rigidbodies need a "gravity" script - Code (csharp): function FixedUpdate() { var closestGravity : GravityGenerator; // find closest gravity generator rigidbody.velocity += ( closestGravity.transform.position - transform.position ) * Time.deltaTime * closestGravity.force; }
Vicenti is basically telling you to turn PhysX gravity off (it's in your project settings, simply change it to 0 - if you can't find it, look at the script reference and do it in code) and then attach the script he has given you to every object that you want to be under the influence of gravity. Tweak things a little to suit your project (ie, does mass matter?)
then i try to save script i have an error: Code (csharp): Assets/NewBehaviourScript 1.js(5,24): BCE0018: The name 'GravityGenerator' does not denote a valid type ('not found').
Well yes, that's to be expected, because "GravityGenerator" is the name of the script class for things which draw other objects towards them. So you need to actually create a script called "GravityGenerator" yourself and make sure it has a field called "force" which contains some suitable value (you'll need to experiment) and then attach this script component to the relevant objects.
now i'm realy confused... maybe its becouse i'm bad at english and some words i dont understand... But realy anyone can't create example scene? or unitypacage. Please. Or video.
You need to walk through one or two of Unity's official tutorials, like the Lerpz platformer or the first-person-shooter. Being able to see where that script goes is one of the most basic abilities in Unity. Since it references "rigidbody.velocity", it's going to be altering the velocity of the object you attach it to. Create a script named Gravity Generator and paste Code (csharp): var force : float = 1.0; var forceDistance : float = 100.0; static var all : Array = new Array(); function Start() { all.Add( this ); } Create a large sphere (we'll call it the planet), make it a GravityGenerator, and set forceDistance to about three times its radius. Make sure it has a collider, though it doesn't need a rigidbody. Create a script named FakeGravity and paste Code (csharp): function FixedUpdate() { var newVelocity : Vector3 = rigidbody.velocity; for ( var GG in GravityGenerator.all ) { var difference : Vector3 = GG.transform.position - transform.position; if ( difference.magnitude < GG.forceDistance ) { var force = (GG.forceDistance - difference.magnitude) / GG.forceDistance * GG.force; newVelocity += difference.normalized * force * Time.deltaTime; } } rigidbody.velocity = newVelocity; } Create a second object, move it outside the sphere, and attach FakeGravity to it. Make sure it has a collider and a rigidbody and that it is unaffected by gravity. Play with the planet's GravityGenerator settings and see what happens. The object should treat the planet like a planet, accelerating faster as it gets closer. Add a second planet and the object will be attracted to both of them. Now your player character just needs to be a FakeGravity rigidbody and they'll be bound by the same rules.
I can't say for sure, but I'm not entirely convinced that the effect shown in the linked webplayer is implemented as a gravity effect. It looks more like the standard 'Mario Galaxy' technique to me, where a ray is cast downwards relative to the player, and if an intersection is found, the player's feet (or whatever) are moved to the intersection point and the player itself is (incrementally) aligned with the surface normal at that point. IIRC, in the webplayer there are cylindrical objects that the player can walk on. You could probably get some sort of gravity-based method to work using a closest-point test, but just having a bunch of 'point' gravity sources isn't going to give you the right effect, I don't think. Again, just speculating, but I'm somewhat doubtful that there's any sort of 'gravity generator' system being used here.
Ah, that sounds about right. Can't believe I didn't think of that. xD I recall there being plenty of specific examples on how to create that kind of system. Try searching the forums for "Mario Galaxy" or "Prey", I think. Basically what you'll do is still disable gravity and implement your own - Code (csharp): var localGravity : Vector3; function Update() { var rch : RaycastHit; if ( Physics.Raycast( transform.position, -transform.up, rch, playerHeight ) ) { localGravity = -rch.normal; } } Then you use localGravity as the direction for your gravity. It's still quite complex to get something as robust as Mario Galaxy, but those are a few of the basics for you.
As I am working on such a system, it makes me feel halfway adequate with C# to know that such a feature is robust and complex. xD It'd be really interesting to see just how Mario Galaxy's system is programmed. I wonder just how lengthy it is by comparison.