I'm currently having a problem in Unity figuring out code to change the direction of gravity on a Character Controller. By this I mean the gravity normally is facing downwards, as gravity normally does, so my character can run left, right and jump as I want him to. But I want to be able to change it so the gravity faces upwards so the character can walk and jump on the roof.
Any help of guidance would truly be brilliant and much appreciated!!!
It should be fairly easy to do. Instead of using the built-in gravity, just implement your own. You first need to set the Use Gravity to false.
Then, you would just apply this script to your objects:
using UnityEngine;
public class ReversibleGravity : MonoBehaviour
{
float gravity = -9.8f;
void Update ()
{
rigidbody.velocity.y += gravity * Time.deltaTime;
}
public void ReverseGravity()
{
gravity = -gravity;
}
}
The slightly harder part would be orienting your character correctly without it "snapping" to the new gravity orientation. I would use spherical interpolation on the Up vector of your objects, like so:
Only one correction, change Update to FixedUpdate nad Time.deltaTime to Time.fixedDeltaTime. There are functions with fixed time step and are not framerate dependant.
no, if you want that kind of "Gravity" use force for the object outside the planet, i mean, use the Universal Gravity Formula with some tweeks that suits you best another explanation every update add force to the walker depending on how close to the planet is, the vector of the force would be something like the distance between planet and walker, and a force calculated value to be able to keep it "walking" no mather it possision in the planet, good luck gqferbs
The link seems to be a bit borked.
– anon63389679fix the youtube link please
– ina