First off I’m not wanting anyone to actually make the code for me. Just a nudge in the right direction is what I’m hoping for.
Now for the actual question. I have a cube serving as the “world” and what I’m trying to do is get the player to be able to jump or move to the edge of the cube and then have its gravity shift 90 degrees to be on the new surface of the cube. Another example could be jumping from the floor and then ending up on the wall shifting the gravity from the floor to the wall, which now serves as the floor. Very similar to some moments in Psychonauts.
Now I’m trying to figure how to go about this. Which method I should be using. Shifting the entire player’s gravity orientation? Then I’d need to do something else with the player’s positional orientation. Or rotate the entire world? Rotating the world seems way too much. I’m using a character controller by the way. But I’m not really sure where I should start.
If anyone knows how to go about starting this suggestions will be very appreciated.
Thank you.
You cannot use built-in gravity, it is Y only. However, built-in gravity is just a simple constant force, so you can make your own with ConstantForce.
You’ll want to rotate the controller, and be very careful with your handling of direction - most existing controller scripts have simplistic world cordite space logic the will not work in your case.
Also be careful with the various Look functions that take a default Up vector of +Y, as you probably want something else.
You could also rotate the world, but that could be costly if it’s many static colliders.
On the trigger that the player would collide with when they fall off a ledge.
public static bool canRotate = false;
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Player")
canRotate = true;
}
And on the trigger near a wall.
public static bool canRotateToWall = false;
void OnTriggerEnter(Collider other)
{
if (other.transform.tag == "Player")
canRotateToWall = true;
}
Keep in mind this is just for one direction. But the other directions should work quite similar. I’m not sure if this is the best or the most efficient way to do it but it works for the gravity shifting portion.