two question. Mario Galaxy Gravity. and piaggio

hello, I have 2 questions.

1 .- I am creating the gravity of planets like Mario Galaxy, it goes very well, but the problem is that I need to control gravity, I know that this will occupy the property "Drag " of of “RigidBody”, but How would be the equation?.

similar to this:

/* 
   FauxGravityAttractor.js 
   Written by Tonio Loewald ©2008 
    
   Attach this script to objects you want to exert Faux Gravity 
*/ 

// Set to true for mono-directional gravity 
var useLocalUpVector : boolean = false; 

// Force applied along gravity up-vector (negative = down) 
var fauxGravity = -10.0; 

function Attract ( body : FauxGravityBody ){ 
   var gravityUp : Vector3; 
   var localUp: Vector3; 
   var localForward : Vector3; 
    
   var t : Transform = body.transform; 
   var r : Rigidbody = body.rigidbody; 

   // Figure out the body's up vector 
   if(useLocalUpVector){ 
      gravityUp = transform.up;    
   } else { 
      gravityUp = t.position - transform.position; 
      gravityUp.Normalize(); 
   } 
    
   // Accelerate the body along its up vector 
   r.AddForce( gravityUp * fauxGravity * r.mass ); 
   r.drag = body.grounded ? 1 : 0.1; 
    
   
}


r.drag = body.grounded ? 1 : 0.1;

but I’m working in C #.

2 .- What should I use for my character makes a piaju (piaggio)?, A Force (AddForce)
or speed (Velocity + =)?

Like this:

please go between “1:08” and “1:12” minutes… thanks.!

Do you need gravity to apply to every object or just your character?

Unity has a global gravity setting that you can use to apply gravity to every rigidbody.

Physics.gravity = new Vector3(0, -1.0F, 0);

Otherwise you may need to use ConstantForce on only your character’s game object.

ConstantForce constantForce = gameObject.AddComponent<ConstantForce>();

constantForce.force = new Vector3(0,-9.14f,0);

trooper : Do you need gravity to apply to every object or just your character?

I need to apply the gravity of each object, as it adapts to the planet that is irregular in shape.

tropper: Otherwise you may need to use ConstantForce on only your character’s game object.

Ok, thanks for your response, i will try make a piaggio with ConstantForce

EDIT.


I used this statement:

constantForce.force = transform.right * 9f;
[/ CODE]

with my own gravity (that I need to work on the misshapen planet):

[CODE]
Rigidbody r = this.rigidbody;
		
r.AddForce( transform.up * fauxGravity * r.mass ); 

[/ CODE]

but I do not work, it is pegad, no movement, I think it must be because I'm adding a downward force to abjo ...
---------------

does r.AddForce get used in the Update() function?
(AddForce will need to be called many times to make the object look like it’s receiving constant gravity)

Also check to make sure your rigidbody’s kinematic property is not checked.

yes, it is in the Update Function and the rigidbody’s kinematic property is unchecked.!

the gravity function (AddForce) works well.

but the ConstantForce(force) is bad!, it don’t work.

Can you paste the code that changes the constant force

ok, no problem.

the code is here:

....
	void Update () {
		AdjustToGravity(); // here a ray for extract the normal of the surface	
		Gravity(); //Here is the gravity simulation		
	        constantForce.force = transform.right * 3f; //Here is the constantforce
	}

	private void Gravity(){
		rigidbody.AddForce( transform.up * fauxGravity * r.mass ); 
	}
....

I think it is gravity, and which exerts a downward force on a permanent basis, then to make another force (right) combine both forces causing the second force (ConstantForce) not take effect.

and that by applying a force majeure, that is:

constantForce.force = transform.right * 9f / / 9 for example.

if it works but not perfect …

Does constantForce.force = transform.right * 3f need to be specific direction. transform.right will mean that the gravity is always making the character go to his right as opposed to the right side of the world.

yes, and i need this!, for adapt to the deform planet.

Help me please!

thanks!

So far I have the following:

  • A ray of the feet of my character.
  • The ray scans the area vector using my character to “Normal”

The problem is:

I can not make my character walk on the planet, because I’m always making a gravity to the vector.

Will you help me please?

if they were so kind to test my code and help me please.