How do I create a wallrun where the player is rotated so the wall becomes his new floor?
It's quite simple. When the player is walking against a wall, he will be rotated so the wall becomes his new floor. All that in a 3d world.
Something like this:
(The arrow is the player with the direction he is facing up(in his view) and the red thing is a object that makes it possible switch between the two walls(similar to the things in mario kart 8))
It would be awesome if someone could help me with that.
The way I would proceed with this is to change the direction of gravity. You will need to create your own gravity functionality though.
To do this your player object still needs a Rigidbody, but you will need to turn off gravity since you will be manipulating it yourself using a ConstantForce
component. The following code allows this
public enum GravityType {NormalGravity, ReverseGravity, RightGravity, LeftGravity}
public float gravityDown = -9.81f;
public float gravityUp = 9.81f;
public float gravityLeft = -9.81f;
public float gravityRight = 9.81f;
private ConstantForce myGravity;
private Rigidbody rigidbody;
void Start()
{
rigidbody = GetComponent<Rigidbody>();
if (rigidbody == null)
{
rigidbody = gameObject.AddComponent<Rigidbody>(); // add a Rigidbody component
}
rigidbody.useGravity = false; // forget about physics default gravity
myGravity = gameObject.GetComponent<ConstantForce>();
if (myGravity == null)
{
myGravity = gameObject.AddComponent<ConstantForce>(); // add a ConstantForce component
}
SetGravity(GravityType.NormalGravity);
}
public void SetGravity(GravityType gravityType)
{
switch (gravityType)
{
case GravityType.NormalGravity:
SetGravity(new Vector3(0, gravityDown, 0)); // set regular gravity
break;
case GravityType.ReverseGravity:
SetGravity(new Vector3(0, gravityUp, 0)); // set regular gravity
break;
case GravityType.RightGravity:
SetGravity(new Vector3(gravityRight, 0, 0)); // set regular gravity
break;
case GravityType.LeftGravity:
SetGravity(new Vector3(gravityLeft, 0, 0)); // set regular gravity
break;
default:
SetGravity(new Vector3(0, gravityDown, 0)); // set regular gravity
break;
}
}
public void SetGravity(Vector3 g)
{
// calculate the necessary force to produce the desired gravity:
myGravity.force = g;
}
Here is a Unity package that demonstrates this (simple but I am sure you will get the gist of it) - you may need to play with the values to get your desired results.
This only shows you how to manipulate gravity. You will need to add the functionality to your controller and make the necessary granges to gravity as needed.